2 输入1行字符,分别统计其中英文字母,空格,数字和其他字符的个数。
3 打印出以下图案 *
* * *
* * * * *
* * * * * * *
* * * * *
* * *
*
刚看完循环控制,这3个题目不会做。学GGJJ帮偶看看呀
[此贴子已经被作者于2005-2-20 16:48:11编辑过]
[此贴子已经被作者于2005-2-20 16:48:11编辑过]
第一个程序: #include <stdio.h>
long factorial(int n) { if(0==n) return 1; else return n*factorial(n-1); }
void main() { int i; long s=0; clrscr(); for(i=1;i<=20;i++){ s+=factorial(i); } printf("The sum is %ld!\n",s); getch(); }
我没有运行不知道 可不可以运行你自己去看看那 main() {int sum, n; printf("input n"); scanf("%d",&n); sum=0; for(n); f(n); sum=sum+f(n); n=n-1; printf("the result is %d",sum); }
int f(int p) {int q, a; a=1; for(p); a=a*p; p=p-1; return(a); }
第二个题目最好是用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); }