C语言程序设计:用辗转相除法求两个整数的最大公约数。
#include<stdio.h>voidwwjt();intgcd(intn,intm){/**********Program**********//*********...
#include<stdio.h>
void wwjt();
int gcd(int n,int m)
{
/**********Program**********/
/********** End **********/
}
main()
{
int n,m,result;
scanf("%d%d",&n,&m);
result=gcd(n,m);
printf("the gcd is %d\n",result);
wwjt();
}
void wwjt()
{
FILE *IN,*OUT;
int m,n;
int i[2];
int o;
IN=fopen("in.dat","r");
if(IN==NULL)
{
printf("Read FILE Error");
}
OUT=fopen("out.dat","w");
if(OUT==NULL)
{
printf("Write FILE Error");
}
for(n=0;n<6;n++)
{
for(m=0;m<2;m++)
{
fscanf(IN,"%d",&i[m]);
}
o=gcd(i[0],i[1]);
fprintf(OUT,"%d\n",o);
}
fclose(IN);
fclose(OUT);
} 展开
void wwjt();
int gcd(int n,int m)
{
/**********Program**********/
/********** End **********/
}
main()
{
int n,m,result;
scanf("%d%d",&n,&m);
result=gcd(n,m);
printf("the gcd is %d\n",result);
wwjt();
}
void wwjt()
{
FILE *IN,*OUT;
int m,n;
int i[2];
int o;
IN=fopen("in.dat","r");
if(IN==NULL)
{
printf("Read FILE Error");
}
OUT=fopen("out.dat","w");
if(OUT==NULL)
{
printf("Write FILE Error");
}
for(n=0;n<6;n++)
{
for(m=0;m<2;m++)
{
fscanf(IN,"%d",&i[m]);
}
o=gcd(i[0],i[1]);
fprintf(OUT,"%d\n",o);
}
fclose(IN);
fclose(OUT);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询