跪求C语言基础编程题 暂时没分 多谢照顾
求助 基础编程题编写一个函数,求三个数的最大公约数。 要求:在main函数中由键盘输入三个数,然后调用编写的这个函数求出三者的最大公约数,在main函数将其输出
读程序写结果:
2009-10-27 11:05
2009-10-27 11:14
2009-10-27 11:31
程序代码:
#include "stdio.h"
#include "conio.h"
max(int a,int b)
{
int t,d;
if(a<b)
{t=a;a=b;b=t;}
while((d=a%b)!=0)
{a=b;b=d;}
return b;
}
main()
{
int i,j,k,d;
int max(int a,int b);
int gonyue(int a,int b,int c);
printf("put three number:");
scanf("%d,%d,%d",&i,&j,&k);
d=gonyue(i,j,k);
printf("dagongyue=%d",d);
getch();
}
gonyue(int a,int b,int c)
{
int i,j,t,s,d;
if(a<b)
{t=a;a=b;b=t;}
if(a<c)
{t=a;a=c;c=t;}
if(b<c)
{t=b;b=c;c=t;}
s=max(a,b);
d=max(s,c);
return d;
}
3楼的发上来了,更简洁,我的也发上来,给大家参考下;
2009-10-27 11:49
2009-10-27 12:00