C语言练习——12.12

#include<time.h>
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

 一、

/*int main()
{
    int arr[] = {1,2,3,4,5,6,7,8,9,10};
    int c = 7;
    int left = 0;
    int right = sizeof(arr)/sizeof(arr[0]) - 1;
    int a = ( left + right) / 2 ;
    scanf("%d",&c);
    while (left <= right)
    {
        int a = (left + right) / 2;
        if ( arr[a] == c)
        {    
            printf("正确\n");
            break;
        }
        else if ( arr[a] < c)
            left = a + 1;
        else if ( arr[a] > c)
            right = a -1;
    }
    printf("wu\n");
    return 0;
}*/

二、
// int main()
// {
    // char w[17] = {'w','e','l','c','o','m','e',' ','t','o',' ','b','i','t','!','!','!'};
    // char a[] = "#################";
    // int b = 0;
    // for (b = 0;b < 9;b++)
    // {
        // a[b] = w[b];
        // a[17-b] = w[16-b];
        // printf("%s\n",a);
    // }
    // return 0;
// }

三、猜数字游戏

// int main()
// {
    // int a = 0;
    // for (a = 0;a < 3;a++)
    // {
        // char c[] = " ";
        // printf("请输入密码>");
        // scanf("%s",c);
        // if (strcmp(c,"12345") == 0)
        // {
            // printf("success");
            // break;
        // }
        // else
        // {
            // printf("重新输入\n");
        // }
    // }
    // return 0;
// }
// void menu()
// {
    // printf("1.继续游戏\n");
    // printf("0.退出游戏\n");
// }
// void game()
// {
    // int num = rand()%100 + 1;
    // int input = 0;
    // while (1)
    // {
        // printf("请输入:");
        // scanf("%d",&input);
        // if (input > num)
        // {
            // printf("大了\n");
        // }
        // else if (input < num)
        // {
            // printf("小了\n");
        // }
        // else
        // {
            // printf("success\n");
            // break;
        // }
    // }
// }

四、
// int main()
// {
    // int input = 0;
    // srand((unsigned)time(NULL));
    // do
    // {
        // menu();
        // scanf("%d",&input);
        // switch(input)
        // {
            // case 1:
                // game();
                // break;
            // case 0:
                // break;
            // default:
                // printf("worry\n");
                // break;
        // }
    // }while (input);
    // return 0;
// }

// int main()
// {
    // int a = 0;
    // int b = 0;
    // int c = 0;
    // scanf("%d %d %d",&a,&b,&c);
    // if (a >= b && b >= c)
        // printf("%d %d %d",a,b,c);
    // else if (a >= c && c >= b)
        // printf("%d %d %d",a,c,b);
    // else if (b >= a && a >= c)
        // printf("%d %d %d",b,a,c);
    // else if (b >= c && c >= a)
        // printf("%d %d %d",b,c,a);
    // else if (c >= a && a >= b)
        // printf("%d %d %d",c,a,b);
    // else
        // printf("%d %d %d",c,b,a);
    // return 0;
// }

// int main()
// {
    // int a = 0;
    // for (a = 1;a < 101;a++)
    // {
        // if ( a%3 == 0)
            // printf("%d\n",a);
    // }
    // return 0;
// }

五、

int main()
{
    int a = 0;
    int b = 0;
    int c = 0;
     scanf("%d %d",&a,&b);
    if (a >= b)
    {
        for (c = b;c > 0;c--)
        {
            if (b%c == 0 && a%c == 0)
            {
                printf("%d\n",c);
                break;
            }
        }
    }
    else
    {
        for (c = a;c > 0;c--)
        {
            if (b%c == 0 && a%c == 0)
            {    
                printf("%d\n",c);
                break;
            }
        }
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值