c语言设计题

来源:百度知道 编辑:UC知道 时间:2024/09/22 06:38:55
求两个整数m和n的最小公倍数,将求出的最小公倍数存入变量t中
#include "stdio.h"
#include "math.h"
#include "conio.h"
#include "stdlib.h"
main()
{ int i;
long int s;
/***********begin***********/

/************end************/
printf("s=%ld\n",s);
NONO(s);
}

NONO( long int y)
{ FILE *f;
f=fopen("E:\\exam\\04200305\\PROGOUT.DAT","w");
fprintf(f,"The Result is :%ld",y);
fprintf(f,"$$$$$$\n");
fclose(f);
}

#include <stdio.h>
//求最大公约数
void GreatestCommonDivisor()
{
while (1)
{
int m = 0, n = 0;
printf("input m: \b");
scanf("%d", &m);
getchar();
printf("input n: \b");
scanf("%d",&n);

if (m == 0 || n == 0) return;
if (m <= 1 || n <= 1)
{
printf("Values should be larger than 1");
continue;
}
int a = (m > n) ? m : n;
int b = (m > n) ? n : m;
int c = 0;
while ((a % b) != 0)
{
c = a % b;
a = b;
b = c;
}
printf("%d and %d GreatestCommonDivisor = %d\n",m,n,b);
printf("%d and %d 最小公倍数为:%d\n",m,n,b/n);
}
}

int main()
{
GreatestCommonDivisor();
return 0;
}