(1)从键盘输入一段英文,编程统计其中出现字母“a”和“E”的个数。

(2)现有一字符串str(其值可在定义时赋给,也可运行时由键盘输入),编程实现以下功能:查找字符串“the”在str中第一次出现的位置(即“the”中’t’在str中的下标)。

(1)程序如下:
#include <stdio.h>
void main()
{
int i=0,j=0;
char c;
printf("请输入:\n");
while((c=getchar())!='\n')
{
if(c=='a')i++;
if(c=='E')j++;
}
printf("a: %d个 E: %d个\n",i,j);
}

(2)程序如下:
#include <stdio.h>
#include <string.h>
void main()
{
char a[30]="asdjttheklthewn",b[10]="the";
printf("str首地址:%x,字符串the第一次出现的位置:%x\n",a,strstr(a,b));
}追问

请问能否用数组啊

追答

第一个吗?完全可以的
#include
void main()
{
int i=0,j=0,k=0;
char str[100];
printf("请输入:\n");
gets(str);
while(str[k++]!='\n')
{
if(str[k]=='a')i++;
if(str[k]=='E')j++;
}
printf("a: %d个 E: %d个\n",i,j);
}

追问

第二个那样就可以吗?第二个能否在后面注解,谢谢!

温馨提示:答案为网友推荐,仅供参考
相似回答