#define _CRT_SECURE_NO_WARNINGS//scanf宏定义
#include<math.h>//当有用到数学里面的函数
#include<stdio.h>
#include<stdlib.h>//冻结屏幕
int main(){
int a, b, c;
printf(“输入两个数字求最大公约数:”);
scanf("%d%d", &a, &b);
c = (a>b) ? b : a;//三目运算符将最小的赋给c
while(a%c != 0 || b%c != 0)//a,b同时能被c整除不执行该循环
{
c–;
}
printf(“最大公约数为:%d\n”, c);
system(“pause”);//防止程序太快看不到运行结果
return 0;
}
求两个数的最大公约数。
最新推荐文章于 2020-01-24 17:05:19 发布