C语言编程 输入一个不超过40个字符的字符串,将其存入数组中,统计并输出字符'a'出现的次数

如题所述

第1个回答  2011-01-15
#include <stdio.h>
int main()
{
char c[40];
int i,n=0;

printf("输入字符串\n");
scanf("%s",c);
for (i=0;c[i]!='\0';i++)
{
if(c[i] =='a')
n++;
}

printf("a的数量为:%d\n",n);
return 0;
}本回答被提问者采纳
第2个回答  2011-01-15
#include<stdio.h>
int main()
{
char s[50];
int i, count=0;
// 读入字符串
scanf( "%s", s );
// 统计a的个数
for( i=0; s[i]!=0; i++ )
if( s[i] == 'a' )
count++;
printf( "a total %d", count );
return 0;
}
第3个回答  2011-01-16
#include "stdio.h"
main()
{
char s[41];
int i,j,t,n;
scanf("%s",s);
n=strlen(s);
for(i=0;i<n-1;i++)
for(j=0;j<n-1;j++)
if(s[j]>s[j+1])
{
t=s[j];
s[j]=s[j+1];
s[j+1]=t;
}
printf("%s",s);
getch();
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网