c语言 一串数字怎么单独识别

来源:百度知道 编辑:UC知道 时间:2024/06/08 18:53:04
*** input numbers between 0 and 99 ***
2 4 6 8 10 20 30 40 50 60 70 80 90 100回车
** Frequencies **
0 ~ 9: 4
10~19: 1
20~29: 1
.
.
80~89: 1
90~99: 1

用键盘打入一连串的数字2 4 6 8 10 20 30 40 50 60 70 80 90 100然后再打回车
就可以计算出 输入了 4个0~9的数字 1个10-19的 1个 20~29的 。。。
如果以连串的数字有0~100以外的数字就会退出这个程序

请指教怎么做?

#include <stdio.h>
#include <stdlib.h>
int main()
{int num,at[10]={0},i;
scanf("%d",&num);
while(num>=0&&num<100)
{at[num/10]++; /*落入哪个区间,相应加一*/
scanf("%d",&num);}
for(i=0;i<10;i++)printf("%d~%d:%d\n",i*10,i*10+9,at[i]);/*输出*/
system("pause");
}

大概思路

char s[20];
int i = 0;
int j = 0;
gets(s);

while(s[i] != '\0')
{

if (s[i] >= 0 && s[i] <= 9)
{
j++;
}
if()
...

i++;
}

就是这样 定义10个变量统计个数 我这个方法比较容易理解
呵呵。
还是要靠自己多练 看现在的代码毕竟不是自己写的 给你个思路吧!嘿嘿