首页 > 试题广场 >

编写一个程序读取输入,直到#,并报告序列ei出现的次数。

[问答题]

编写一个程序读取输入,直到#,并报告序列ei出现的次数。

此程序必须要记住前一个字符和当前的字符。用诸如“Receive your eieio award.”的输入测试它。

推荐
#include<stdio.h>
int main(void)
{
 char former=0,present;
 int count=0;
 while((present=getchar()) != '#')
 {
 if((former == 'e') && (present == 'i')) count++;
 former = present;
 }
 printf("ei has appeared %d times\n",count);
 return(0);
}

发表于 2018-05-05 21:39:13 回复(0)