2 输入1行字符,分别统计其中英文字母,空格,数字和其他字符的个数。
3 打印出以下图案 *
* * *
* * * * *
* * * * * * *
* * * * *
* * *
*
刚看完循环控制,这3个题目不会做。学GGJJ帮偶看看呀
[此贴子已经被作者于2005-2-20 16:48:11编辑过]
第二个题目最好是用switch语句了; 但是我忘了格式 给你一个错误的 修一下吧 呵呵 #include <stdio.h> void main() { int letter=0,space=0,number=0,others=0; printf("Please input one line characters:\n"); while((c=getchar())!='\n'){ switch(c) case 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z': letter++;break; case '1','2','3','4','5','6','7','8','9','0': number++;break; case ' ': space++;break; default: others++;break;
} printf("letter=%d\t,space=%d\t,number=%d\t,others=%d\n",letter,space,number,others); }