level 1
1,带统计功能的打字联系程序 字符统计:每输入一个字符,字符个数加1 行数:每键入一个回车键,行数加1 单词:单词由字母组成,若输入的字母分列则认为是一个单词 单词之间用空格键分隔。(输入-1为整个文字段的输入结束)答案://////////////////////////////////////////////////////// #include
#include
main() { int i=0,j=0; char *p; printf("Input the words:\n"); while(*p!='-') { *p=getchar(); if((int)*p==32) i++; else if((int)*p==10) i++,j++; } printf("word=%d\n",i); printf("line=%d\n",j); } ////////////////////////////////////////////// 运行过程 Input the words: test 1 23 4 56 789 a bc de fgh 1a 2b3cd 4e hello word -1 word=15 line=5 Press any key to continue...
2006年06月12日 15点06分
1
#include
main() { int i=0,j=0; char *p; printf("Input the words:\n"); while(*p!='-') { *p=getchar(); if((int)*p==32) i++; else if((int)*p==10) i++,j++; } printf("word=%d\n",i); printf("line=%d\n",j); } ////////////////////////////////////////////// 运行过程 Input the words: test 1 23 4 56 789 a bc de fgh 1a 2b3cd 4e hello word -1 word=15 line=5 Press any key to continue...