蓝欧--lesson5<有难度>

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {

//输出数组中4个数的最大数
//    int i = 0, max = 0,a[4] = {0};
//    printf("请输入四个数:");
//    for (i = 0; i<4; i++) {
//        scanf("%d", &a[i]);
//    }
//    max = a[0];
//    for (i = 1; i < 4; i++) {
//        if (a[i] > max) {
//            max = a[i];
//        }
//    }
//    printf("max = %d\n", max);

//    int sum = 0, i = 0 ,a[20];
//
//    for (i = 0; i < 20; i++) ;
//    scanf("%d", &a[i]);
//    sum = sum + a[i];
//    printf("%d",sum);
//}
//
//

//求最大公约数,最小公倍数
//    int a = 0 , b = 0;
//    printf("输入两个数:");
//    scanf("%d %d", &a, &b);
//    int num1 = 0,num2 = 0;
//    int team = a % b;
//    while (team != 0) {
//        num1 = num2;
//        num2 = team;
//        team = num1 % num2;
//        
//    }
//    printf("最大公约数是%d", num2);
//    printf("最小公倍数是%d", a * b / num2);
//    
//}

//    int a = 0, b = 0;
//    int team = 0,num1 = 0,num2 = 0;
//    printf("please:");
//    scanf("%d %d", &a, &b);
//    if (a > b)
//         num1 = a;
//         num2 = b;
//         team = num1 % num2;
//   while (team != 0) {
//        num1 = b;
//        num2 = team;
//        team = num1 % num2;
//        
//    }
//    printf("%d",num2);
//
//
//}
    //一维数组
    //定义一个整型数组,数组5个元素
//    int array[5] = {9,2,3,4,5};
//    printf("%d", array[2]);
//    }
    //数组3个元素,每个都为0
//    int array[3] = {0};
    //数组5个元素,下表为0的是3,其余的都是0
//    int array[5] = {3};
    //定义数组的时候,[]只能是常量或者常量表达式
//    int array[2+2] = {4,7};
    
    //数组里的每个元素都市变量
    //使用数组元素:数组名[下标],下标从零开始,到元素个数-1;
    //使用数组的时候[]里面可以是变量
    //定义数组和是使用数组的区别:前面是否有类型修饰符;
//    int array[6] ={1,2,5,8,6,199};
//    
//    int i = 2;
//    array[i] = 9;
////    for(int b = 0; b < 5; b++){
////        printf("%d, ", array[b]);
////    }
//    printf("更换的数字%d\n",array[i]);
//    
//    printf("%lu",sizeof(array));
//}

//sizeof 用来测试一个变量或者一个数据类型所占用的空间
    //数组所占的内存空间 = 数组元素个数 * 元素类型(是一段连续的内存空间)
    //long a = 10;
    //printf("%lu\n",sizeof(a));
    //}
//    
//    //使用数组,要注意不要让下标越界,否则危险
//    //定义数组时候,[] 可以不写元数个数,那么默认会看数组初始化是给了几个元素
//    int array[3] = {1,5,2,54};
//    //这个数组只能储存一个元素
//    int  array[] = {0};
    
    //这个数组只能储存一个元素,显示4字节
//    int array[] = {0};
//    printf("%lu",sizeof(array));
//}

//    double array[3] = {14,23.34,41};
//    printf("%lu",sizeof(array));
//}
 
    //  \t 输出一个Tab键
//    int array[5] = {12,32,4,3,2};
//    for (int i = 0; i < 5; i ++) {
//        printf("%d\t", array[i]);
//    }
//}

//    int array[] ={2,3,4,5,1,7};
//    for (int i = 0; i < 6; i++) {
//        printf("array[%d] = %d\n", i, array[i]);
//        }
//    printf("字节总共是%lu",sizeof(array));
//    }
//

//    int array[10]= {0};
//    for (int i = 0; i < 10; i++) {
//        array[i] = arc4random() % 101;
//        printf("%d\t",array[i]);
//    }
//}

//    int array[58] = {0};
//    for (int i = 0; i < 58; i++) {
//        array[i] = arc4random() % 101 +100;
//        printf("%d\t",array[i]);
//    }
//}
    //数组是整体,不能够直接参与运算,只能单个元素运算
//    int a[2] ={1,2};
//    int b[2] = {0};
//    a = b;//是错误的
//

//    int array[20] = {0},sum = 0;
//    for (int i = 0; i < 20; i++) {
//        array[i] = arc4random() % 41 + 30;
//        sum +=array[i];
//        printf("%d\t",array[i]);
//    }
//    printf("和是%d",sum);
//}
//    
//    int array[15];
//    int sum = 0;
//    for (int i = 0; i < 15; i++) {
//        array[i] = arc4random() % 41 + 30;
//        printf("%d\t",array[i]);
//          sum += array[i];
//          }
//        printf("总和sum = %d", sum);
//        }

//    int array1[5] = {1,2,3,4,5},array2[5] = {0};
//    for (int i = 0; i < 5; i++) {
//        array2[i] = array1[i];
//    printf("%d\t",array2[i]);
//    }
//}

//    int array[10] = {9,6,38,265,23,65,3},array1[8] = {0};
//    for (int i = 0; i < 8; i++) {
//        array1[i] = array[i];
//        printf("%d\n",array1[i]);
//    }
//}

//两列打印
//    int array[10] = {0},array1[10] = {0};
//    for (int i = 0; i < 10; i++) {
//        array[i] = arc4random()%101;
//        printf("%d\t",array[i]);
//        array1[i] = array[i];
//        printf("%d\n",array1[i]);
//    }
//}
 
//--------------------------------------------------------------------
//    //两行打印
//    int array[10] = {0},array1[10] = {0};
//    for (int i = 0; i < 10; i++){
//        array[i] = arc4random() % 101;
//        printf("%d\t",array[i]);
//        array1[i] = array[i];
//      }
//    printf("\n");
//    for (int i = 0;i < 10; i++) {
//        printf("%d\t",array1[i]);
//    }
//}
//----------------------------------------------------------------------
//    int array[10] = {0},array1[10] = {0},array3[10] = {0};
//    for (int i = 0; i < 10; i++) {
//        array[i] = arc4random() % 21 + 20;
//        array1[i] = arc4random() % 21 +20;
//        array3[i] = array[i] + array1[i];
//    printf("arra3[%d]%d\t", i, array3[i]);
//    }
//}

//    int a[10] = {0},b[10] = {0},c[10] = {0};
//    for (int i = 0; i < 10; i++) {
//        a[i] = arc4random() % 21 + 20;
//        b[i] = arc4random() % 21 + 20;
//        c[i] = a[i] +b[i];
//        printf("%d + %d = %d\n",a[i],b[i],c[i]);
//    }
//
//}
 
//++++++++++++++++++++++++++++ //冒泡排序++++++++++++++++++++++++++++++++
//
//    int array[10] = {0};
//    for (int i = 0; i < 10; i++) {
//        array[i] = arc4random() % 51+50;
//            printf("%d\t",array[i]);
//    }
//    printf("\n");
//    //外层循环控制比较趟数
//             for (int i = 0; i < 10 - 1; i++){
//                 //内层循环控制每趟的比较次数
//                 //每趟比较次数,随着趟数的增加越来越少
//                 for (int  j = 0;j < 10 - 1 -i ;j++){
//                    //如果前面的数比后面的数大,则交换
//                     if(array[j] >array[j + 1]){
//                         int  temp = array[j];
//                         array[j] = array[j + 1];
//                         array[j + 1] = temp;
//                     }
//                         
//                 }
//            }
//    printf("\n");
//    for (int i = 0; i < 10; i++) {
//        printf("%d\t",array[i]);
//    }
//}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//    int arrray[10] = {0};
//    for (int i = 0; i < 10; i++) {
//        arrray[i]= arc4random() % 51 + 50;
//        printf("%d\t",arrray[i]);
//    }
//         for (int i = 0;i < 10-1; i++){
//             for (int j = 0;j <10-1-i; j++){
//                 if (arrray[j]>arrray[j + 1]){
//                     int team = arrray[j];
//                     arrray[j] = arrray[j + 1];
//                     arrray[j + 1] = team;
//                 }
//             }
//         }
//         printf("\n");
//         for (int i = 0;i < 10; i++){
//             printf("%d\t",arrray[i]);
//         }
//        }
    
    
//    int array[5] = {9,2,3,4,5};
//    int max = array[0];
//    for (int i = 0; i < 5; i++) {
//        if (max > array[i]){
//            max = array[i];
//            printf("%d,",array[i]);
//  
//        }else{
//            printf("%d,",max);
//        }
//    }
//}

//----------------------------//选择排序----------------------------------

//    int array[10] = {0};
//    for (int i = 0; i < 10;i++){
//        array[i] = arc4random() % 31 + 30;
//        printf("%d\t",array[i]);
//    }
//    //外层循环控制趟数
//    for (int i = 0; i < 10 - 1; i++) {
//        int minIndex = i;
//        //如果当前数,比最小值更小
//        for (int j = i + 1; j < 10; j++ ){
//            if (array[j] < array[minIndex]){
//                //更新最小值下标
//                minIndex = j;
//            }
//        }
//        //一趟结束之后如果最小值的下标和开始的时候假定的不是同一个,则交换
//        if (minIndex != i){
//            int temp = array[i];
//            array[i] = array[minIndex];
//            array[minIndex] = temp;
//        }
//        
//        }
//    printf("\n");
//    for (int i = 0; i < 10; i++) {
//        printf("%d\t",array[i]);
//    }
//}

//-----------------------------------------------------------------------
//    int array[8] = {0};
//    for (int i = 0; i < 8; i++) {
//        array[i] = arc4random() % 51 + 50;
//        printf("%d\t",array[i]);
//    }
//
//    for (int i = 0; i < 8 - 1; i++) {
//        int minIndex = i;
//        for (int j = i + 1; j < 8; j++) {
//            if (array[j] < array[minIndex]){
//                minIndex = j;
//            }
//        }
//        if (minIndex != i){
//            int temp = array[i];
//            array[i] = array[minIndex];
//            array[minIndex] =temp;
//        }
//    }printf("\n");
//    for (int i = 0; i < 8; i++) {
//        printf("%d\t",array[i]);
//    }
//}

//字符数组(字符串)//下面两种都正确,而且效果一样
//    char str[10] = {‘i‘,‘p‘,‘h‘,‘o‘,‘n‘,‘e‘};
//    
//    char str1[10] = "iphone";
//    for (int i = 0; i < 10; i++) {
//        printf("%c",str1[i]);
//    }
//}
    
    //%s 用来输出字符串,直接跟数组名
    //%s  的工作原理,从数组的第一个元素输出,到\0结束
//    char str1[10] = "iphone";
//    printf("%s",str1);
//}
//    char str1[10] = "iphone";
//    str1[3] = ‘\0‘;
//    printf("%s",str1);
//}

//    char str1[10] = "iphone";
//    str1[3] = ‘\0‘;
//    for (int i = 0; i < 10;i++ ){
//        printf("%c",str1[i]);
//    }
//}

//    //数组是6个元素
//    char str[] = {‘i‘,‘p‘,‘h‘,‘o‘,‘n‘,‘e‘};
//    //此种写法编译器会自动补一个\0,数组是7个元素
//    //重用:\0
//    char str1[] = "iphone";
//    printf("str = %lu\n",sizeof(str));
//    printf("str1 = %lu\n",sizeof(str1));
//    printf("%s\n",str);
//    printf("%s\n",str1);
//}

//    char str[] = {‘a‘,‘p‘, ‘p‘,‘l‘,‘e‘,‘\0‘};
//    char stra[] = "apple";
//    printf("%s\n",str);
//    printf("%s\n",stra);
//    printf("str = %lu, str1 = %lu",sizeof(str),sizeof(stra));
//}
     //(1)strlen()计算字符串长度
    
    //sizeof 运算符,用来测算数据类型或者变量所占内存空间
    //strlen() 是一个函数,用来计算字符串的长度,是不含\0的
    
//    char string[] = "abcdefghijklmnupqrstuvwxyz\0";
//    char strings[10] = {‘a‘};
//    unsigned long length = strlen(strings);
//    printf("%lu",length);
//}

//(2)strcpy 字符串拷贝
//    char str1[20] = "aaaaaaaaaaaa";
//    char str2[20] = "iphone";
    //把str2里面的内容拷贝到str1中,拷到\0结束
    //被拷入的字符串,内存的足够大,否则危险
//    strcpy(str1, str2);
//    printf("%s",str1);
//}
//    char str1[] = "aaaaaaaaaaaa";
//    char str2[5] = {‘a‘,‘b‘,‘c‘,‘d‘,‘e‘};
//    strcpy(str1, str2);
//    printf("%s",str1);
//}

//(3)strcat() 字符串拼接
    //把str2的内容拼到str1后面
    //被拼入的字符串内存足够大
//    char str1[100] = "iphone ";
//    char str2[100] = "android";
//    strcat(str1, str2);
//    printf("%s",str1);
//}
//    char str1[100] = " apple ";
//    char str2[100] = "iphone";
//    char str3[100] = "name";
//    strcat(str2, str1);
//    strcat(str2, str3);
//    printf("%s",str2);
//}
   
    
    //strcmp()字符串比较
//    char str1[5] = "abcee";
//    char str2[6] = "aaaaa";
//    //比较两个字符串是否相等,返回的是ASCII码的差值
//    //相等的话,得到的结果是0;
//    int result = strcmp(str1, str2);
//    printf("%d",result);
//}

//查找字符串中的空格数:例如:“I love iOS, i want an iPhone5s”6个空格
//    char str[] = "I love ios, i want an iphone6 plus!";
//    int blank = 0;
//    int i = 0;
//    while (str[i] != ‘\0‘) {
//        if (str[i] == ‘ ‘){
//            blank++;
//        }
//        i++;
//    }
//    printf("%d",blank);
//    
//}

时间: 2024-10-16 03:06:51

蓝欧--lesson5<有难度>的相关文章

蓝欧--lesson8

#import <Foundation/Foundation.h>//       宏名 替换的内容[千万别加分号]#define VALUE 10 //命名规范,纯大写或者是k开头的驼峰命名法#define AS 52.02 #define SUM(A, B) A + B #define SQUARE(A) ((A) + (A))//安全 #define MAXXX(A, B) (((A) > (B)) ? (A) : (B)) #define MAX_NUMBER(A, B, C)

蓝欧h5课程笔记

1.获取css外部样式表的属性值 getCss(obj,'属性名称');如:getCss(oSpan[0],'height'); getComputedStyle(obj).属性名称;如:getComputedStyle(oDiv[0]).width; 2响应式布局 <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0

蓝欧证件照

蓝欧--lessonc12[函数指针]

#import <Foundation/Foundation.h> //int(*)(int ,int) 原类型//PFUN 新类型typedef int(*PFUN)(int ,int); typedef struct student{    char name[20];    char sex;    int age;    float score;}STUDENT; BOOL sortByAge(STUDENT stu, STUDENT stu1);BOOL sortByAge(STUD

蓝欧--lesson2

#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) {                //变量定义三要素    //类型修饰符 变量名 =初始值            //变量命名规范:    //1.变量名必须以字母,数字,下划线组成,数字不能打头    //2.变量名不能够占用系统关键字    //3.见名知意    //4.驼峰命名法        //    int a = 5;//   

蓝欧--lessonc11[动态内存分配]

#import <Foundation/Foundation.h>#import "header.h" typedef struct student{    char name[20];    char sex;    int  age;    float score;    }STUDENT; int maxValue(int a, int b);int square(int n); char * getString(); int maxValue(int a, int

蓝欧培训 c7

header.m#import "header.h" void printStudent(STUDENT boy){    printf("%-11s %d %d-%d-%d %c %.2f\n",boy.name,boy.age,boy.birthday.year,boy.birthday.month,boy.birthday.day, boy.sex,boy.score); } void printAllStudents(STUDENT stus[],int c

蓝欧--lesson3

#import <Foundation/Foundation.h>////int main(int argc, const char * argv[]) { //    //    //溢出//    char a = 128;//    //    printf("%d", a);//        //无符号类型,值存正数    //%u 打印无符号整型数    //%lu 打印无符号长整型数    //%ld 打印有符号长整型数//    unsigned char

蓝欧--lessonc10[指针高级]

hearder.m #import "hearder.h" void changeValue(int *number) {    *number = 100; } void swap(int * a, int * b){    printf("a = %d,b = %d\n", *a, *b);    int tem = *a;    *a = *b;    *b = tem; } void maxThreeNumber(int a, int b, int c, i