c语言中需要注意的一些地方

   
1.    (a, b)
    unsigned int random = arc4random() % (b - a + 1) + a;

    无符号长整形数据
    int a = 100;
    printf("%lu\n", sizeof(a));
    printf("%lu\n", sizeof(int));
    
    

   

2.break与continue的区别 

    int i1 = 1;
    
    while(1){
        if (i1 > 100){
            break;             //break可以跳出任意循环。向下跳
        }
        printf("%d\n", i1);
        i1++;
    }

    


    
    int i2 = 1;
    
    while(i2 <= 100){
        if (i2 % 2 != 0){
            i2++;
            continue;             //continue向上跳
        }
        printf("%d\n", i2);
        i2++;
    }
    
    
    
注意:贪婪法:a +++ b
    
    
    
3.辗转相除法
    int a = 0, b = 0;
    printf("Enter two number: ");
    scanf("%d%d", &a, &b);
    
    while(a % b != 0){
        int temp = a % b;
        a = b;
        b = temp;
    }

    printf("maxGY = %d\n", b);



4.随机生成一个数,这个数的范围在[10,20]或[80,90],要求用四种不同方法;

//(1)
    unsigned int random = 0;
    switch (arc4random() % 2) {
        case 0:
            random = arc4random() % (20 - 10 + 1) + 10;
            break;
        case 1:
            random = arc4random() % (90 - 80 + 1) + 80;
            break;
        default:
            break;
    }
    
    

//(2)

    unsigned int random = 0;
    random = arc4random() % (20 - 10 + 1) + 10 + (arc4random() % 2) * 70;
    
    printf("random = %d\n", random);
    
    
//(3)
    unsigned int random = 0;
    random = arc4random() % 22;
    if (random < 11) {
        random += 10;
    } else {
        random += 69;
    }
    printf("random = %d\n", random);
    
    

//(4)
    random = arc4random() % (30 - 10 + 1) + 10;
    if (random > 20) {
         andom += 59;
    }




注意:int (*p)[7] = array;            //二维数组指针
            int *p1[7] = {NULL};        //指针数组



    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值