三个数的大小判断,输出0到100中的3的倍数,两个数的最大公约数
作者:互联网
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
//三个数按从大到小的输出
int main()
{
int a = 0;
int b = 0;
int c = 0;
printf("请输入三个数:");
scanf("%d%d%d", &a, &b, &c);
if (a<b)
{
int x = a;
a = b;
b = x;
}
if (a<c)
{
int x = a;
a = c;
c = x;
}
if (b<c)
{
int x = b;
b = c;
c = x;
}
printf("%d %d %d", a, b, c);
return 0;
}
//输出0~100中3的倍数
int main()
{
int i = 1;
for ( i = 1; i < 100; i++)//方法1
{
if (i%3 == 0)
{
printf("%d ", i);
}
}
printf("\n");
for ( i = 3; i < 100; i+=3)//方法2
{
printf("%d ", i);
}
return 0;
}
//两个数的最大公约数的输出
int main()//方法1
{
int a = 0;
int b = 0;
printf("请输入两个数:");
scanf("%d%d", &a, &b);
int max = 0;
if (a > b)
{
max = b;
}
else
max = a;
while (1)
{
if (a%max == 0 && b%max == 0)
{
printf("最大公约数为:%d", max);
break;
}
max--;
}
return 0;
}
int main()//方法2
{
int m = 0;
int n = 0;
int t = 0;
printf("输入两个数:");
scanf("%d%d", &m, &n);
while (t= m%n)
{
m = n;
n = t;
}
printf("最大公约数为:%d", n);
return 0;
}
标签:return,int,max,d%,最大公约数,倍数,printf,100 来源: https://blog.csdn.net/csdn_1997/article/details/123216001