南里侑香 除名:请比较有耐心的高手帮我讲解一下此题!(c语言)

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/11 19:54:00
# include <stdio.h>
main()
{ int c,i,nwhite,nother,ndigit[10];
nwhite=nother=0;
for(i=0;i<10;++i) ndigit[i]=0;
while((c=getchar())!='\n')
if(c>='0'&&c<='9')
++ndigit[c-'0'];
else if(c==''|| c=='\t')
++nwhite;
else ++nother;
printf("\ndigits frequency");
for (i=0;i<10;++i)
printf("\n %d %d",i,ndigit[i]);
printf("\n white space: %d,\n other: %d\n",nwhite,nother);
}
原来是这个啊,我没注意不好意思哈,我追加100分行了吧

# include <stdio.h>
main()
{ int c,i,nwhite,nother,ndigit[10];
nwhite=nother=0;
for(i=0;i<10;++i) ndigit[i]=0; //数组所有元素赋初值0;
while((c=getchar())!='\n') //输入字符直到接收到换行符'\n'为止
if(c>='0'&&c<='9') //当接收的字符在0-9之间的话,ndigit[c-'0']计数即是加1.c-'0'的结果刚好就是其数的下标值
++ndigit[c-'0'];
else if(c==''|| c=='\t') //当不是0-9之间的字符里面如果是空格或者TAB时,让nwhite加1来统计空格和TAB的个数
++nwhite;
else ++nother; //如果不是数字和空格及TAB的就统计在nother变量里
printf("\ndigits frequency");
for (i=0;i<10;++i)
printf("\n %d %d",i,ndigit[i]); //输出一行里不同数字的个数
printf("\n white space: %d,\n other: %d\n",nwhite,nother);//输出空格数,和非数字和空格的个数。
}

没分那有那耐心~~你知道就那点东西写出来过程要你懂得写多少吗?一分不给真抠门

该程序有点小问题,修改后如下:(上机调试过了);另外上楼的那个讲得很不错!!!很有耐心!!!
# include <stdio.h>
void main()
{
int c,i,nwhite,nother,ndigit[10];
nwhite=nother=0;
for(i=0;i<10;++i)
ndigit[i]=0;
while((c=getchar())!='\n')
if(c>='0'&&c<='9')
++ndigit[c-'0'];
else if(c==' '|| c=='\t')
++nwhite;
else ++nother;
printf("\ndigits frequency");
for (i=0;i<10;++i)
printf("\n %d %d",i,ndigit[i]);
printf("\n white space: %d,\n other: %d\n",nwhite,nother);
}

请你比较耐心的将悬赏分选择200