输入一串大小写字母,并实现如下功能:
输入一串大小写字母,并实现如下功能:(1)不允许输入除了大小写字母之外的其他字符;
(2)找出其中的大写字母“A”,并输出其位置,比如输入的字母BDAefA,
则输出“字母A在第3 ,6位!”
程序代码:#include <stdio.h>
#include <ctype.h>
int main()
{
int i=0,j=0,a[10]={0};
char s[10],ch;
while(i<9)
{
ch=getchar();
if(isalpha(ch))
{
s[i]=ch;
if(ch=='A')
{
a[j]=i+1;
j++;
}
i++;
}
}
s[9]='\0';
printf("\nThe string you have input is:%s\n",s);
printf("\nThe position of A is:");
for(i=0;a[i]!=0;i++)
{
printf("%3d",a[i]);
}
return 0;
}

程序代码:#include <stdio.h>
#include <ctype.h>
int main()
{
int i=0,j=0,a[10]={0};
char s[10],ch;
while(i<9)
{
ch=getchar();
if(isalpha(ch))
{
s[i]=ch;
if(ch=='A')
{
a[j]=i+1;
j++;
}
i++;
}
else
{
printf("\nYou should input a alpha,not something else!\n");
}
}
s[9]='\0';
printf("\nThe string you have input is:%s\n",s);
printf("\nThe position of A is:");
for(i=0;a[i]!=0;i++)
{
printf("%3d",a[i]);
}
return 0;
}
