计算机等级 > 二级考试 > C语言程序设计 > C语言模拟试题 > 文章内容

全国计算机等级考试C语言考试程序设计题(12)

2016-6-8编辑:ljnbset

在考生文件夹下,要求程序PROG.C的功能是:

求两个整数m和n的最大公约数,m和n的值由键盘输入。

 

#include "stdio.h"

   int fun(int m,int n)

  {

  /***********begin***********/

int t;

t=n%m;

if(t!=0) fun(n,t);

return m;

 

 

 

 

 

 

 

 

 

 

  /************end************/

  }

 

  void main()

  {

    void  NONO( );//函数声明

   int m,n,i,t;

    printf("Enter m,n :\n");

    scanf("%d,%d",&m,&n);

    if(m>n) { t=m; m=n; n=t; }

printf("The Highest Common Divisor of %d and %d is %d\n",m,n,fun(m,n));

    NONO( );

  }

 

void  NONO( )

  { FILE  *fr,*fw;

    int i,m,n;

    fr=fopen("PROGIN.DAT","r");

    fw=fopen("PROGOUT.DAT","w");

    for(i=1;i<=5;i++)

    { fscanf(fr,"%d,%d",&m,&n);

      fprintf(fw,"Maximal Common Divisor Of %d and

%d is %d\n",m,n,fun(m,n));}

    fclose(fr);

    fclose(fw);

  }

全国计算机等级考试C语言考试程序设计题(11)

热点推荐

登录注册
触屏版电脑版网站地图