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>
#define MAX 100
int a[MAX], b[MAX], count = 0;
void rData()
{ int i;
FILE *fp;
fp = fopen("C:\\100.dat", "r");
for (i=0; i<MAX; i++)
fscanf(fp, "%d,", &a[i]);
fclose(fp);
}
void main()
{ int i;
rData();
//printf("满足条件的数= ......
源码:
# include <stdio.h>
int main()
{
/* 定义字符型变量,并给它们付初值 */
char c1, c2, c3, c4, c5, c6, c7;
c1 = 'C';
c2 = 'h';
c3 = 'i';
c4 = 'n';
& ......
源码:
# include <stdio.h>
int main()
{
int x, y;
printf("请输入自变量x:");
scanf("%d", &x);
if(x < 6)
{
  ......
源码:
# include <stdio.h>
int main()
{
/* sex代表输血者的性别,weight代表输血者的体重,cubage代表输血量 */
int sex, weight, cubage;
printf("请给出输血者的性别(女性为负数)和体重:(用逗号隔开)");
&nbs ......
源码:
# include <stdio.h>
int main()
{
int i, j, k;
/* 变量i从0到4,表示所画菱形图的第一至第五行 */
for(i = 0; i <= 4; i++)
{
/* ......