C_使用while语句求两整数的最小公倍数与最大公约数
源码:
# include <stdio.h>
int main()
{
int x, y, num1, num2, temp;
printf("请输入两个正整数:\n");
scanf("%d %d", &num1, &num2);
if(num1 < num2)
{
temp = num1;
num1 = num2;
num2 = temp;
}
x = num1;
y = num2;
while(y != 0)
{
temp = x%y;
x = y;
y = temp;
}
printf("它们的最大公约数为:%d\n", x);
printf("它们的最小公倍数为:%d\n", num1*num2/x);
return 0;
}
相关文档:
源码:
# include <stdio.h>
int main()
{
/* 定义了一个无符号字符型变量,此变量只能用来存储无符号数 */
unsigned char result;
int a, b, c, d;
a = 2;
b = 4; ......
源码:
# include <stdio.h>
int main()
{
int x, y, z, mid, dec;
printf("请任意输入三个整数:\n");
scanf("%d %d %d", &x, & ......
源码:
# include <stdio.h>
int main()
{
int num;
/* 下面定义的各变量,分别代表个位,十位,百位,千位,万位,十万位以及位数 */
int indiv, ten, hundred, thousand;
int ten_thousand, hundred_thous ......
源码:
# include <stdio.h>
int main()
{
int i, j, k;
/* 变量i从0到4,表示所画菱形图的第一至第五行 */
for(i = 0; i <= 4; i++)
{
/* ......