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

全国等级考试资料网 2022-09-17 18:19:12 64

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

统计字符串中元音字母’a’、’e’、’i’、’o’、’u’的个数并输出。

    例如,当字符串为"This Is a c Program"

              输出:Result is: 4

 

#include

  #include

  int fun(char str[])

  {

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

int s=0,i=0;

   while(str[i]!=’’)

   {

   if(str[i]==’a’ || str[i]==’e’ || str[i]==’i’ || str[i]==’o’ || str[i]==’u’)

          s++;

   i++;  

   }

   return s;

 

 

 

 

 

 

 

 

 

 

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

  }

  void main()

  {

    void NONO( );//函数声明

    char str1[80];

    int n;

    printf("Enter str1 : ");

    gets(str1);

     n=fun(str1);

    printf("Result is: %d ",n);

    NONO( );

  }

 

  void NONO( )

  { FILE  *fr,*fw;

    int i;

    char s[80];

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

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

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

    { fgets(s,80,fr);

      fprintf(fw,"TheResult is:%d ",fun(s));

    }

    fclose(fr);

    fclose(fw);

  }

相关资料

相关阅读