else if(c==' ') space++;
else other++;
}
printf("digital=%d,space=%d,other=%d\n",digital,space,other);
}
A-7、输入一行字符,统计其中有多少个单词,单词之间用空格符分隔开。
#include<stdio.h>
void main(){
char c;
int flag=1,word=0;
printf("please input a string:\n");
while((c=getchar())!='\n'){
if(c==' ') flag=1;
else{
if(flag){
word++;
flag=0;
}
}
}
printf("word=%d\n",word);
}
A-8、从键盘输入一个 099999 之间的整数。
① 判断它是一个几位数;
② 将该数的各位数字按逆序输出。
#include<stdio.h>
void main(){
long num;
int count=0;
printf("please input an integer between 0 and 99999:\n");
scanf("%ld",&num);
do{