不知道是帮了你还是害了你,你学什么的,多大了,这些是最基础的题,很简单的,自己多看看书吧,这些程序都试过,可以运行,自己好好看看 1. #include <stdio.h> main() { int x,y; printf("please input x :"); scanf("%d",&x); /*下面三句可以用这一句代替: y=(x<0)?(x-1):(x=0?0:1);*/ if(x<0) y=x-1; else if(x==0) y=0; else y=1; printf("the value of y=%d",y); getch(); } 2. #include <stdio.h> main() { int h,i,s; s=560; h=s/60; i=s%60; printf("%d minutes equals %d hours %dminutes",s,h,i); getch(); } 3. #include <stdio.h> main() { int a,b,c,d,max,temp; max=0; temp=0; printf("please input the value of a,b,c,d:\n"); scanf("%d%d%d%d",&a,&b,&c,&d); /*以下六行可被这一行代替: max=(a>b?a:b)>(c>d?c:d)?(a>b?a:b):(c>d?:d);*/ if(a>=b)max=a; else max=b; if(c>=d)temp=c; else temp=d; if(max<temp)max=temp; printf("the max of a,b,c,d is %d ",max); getch(); } 4 #include <stdio.h> main() { char c; int character=0 ,number=0,space=0 ,others=0; /* 输入 abcdefg1234 <><> 输出 character=7 number=4 space=3 others=5 */ do { c=getchar(); if(c>='a'&&c<='z'||c>='A'&&c<='Z')character++; else if(c>='0'&&c<='9')number++; else if(c==' ')space++; else others++; } while(c!='\n') ; printf("character=%d\nnumber=%d\nspace=%d\nothers=%d\n",character,number,space,others); getch(); } 5. #include <stdio.h> main() { printf(" * * * * * * * ** *\n"); printf(" * * * * * * * * * *\n"); printf(" * * * * * * * * * *\n"); printf(" * * * * * * * * * *\n"); getch(); } 6. #include <stdio.h> main() { int i=0; int j=0; printf(" "); for(;i<5;i++) { for(j=5-i;j>0;j--) printf(" "); printf("@"); for(j=0;j<i;j++) printf("@@"); printf("\n"); } getch(); } 7. #include <stdio.h> float a(float n) { float an; if(n<1) return -1; else if(n==1) an=1; else an=a(n-1)+(2*n-1)/(n*n); return an; } main() { float n; printf("please input n:"); scanf("%f",&n); printf("a(n)=%f",a(n)); getch(); } 8. #include <stdio.h> int a(int n) { int i,an=0; for(i=1;i<=n;i++) { an+=i; } return an; } main() { int n; printf("please input n:"); scanf("%d",&n); printf("a(n)=%d",a(n)); getch(); } 9. #include <stdio.h> int a(int n) { int i,an=0; for(i=1;i<=n;i++) { if(i%2==1) an+=2*i-1; else an-=2*i-1; } return an; } main() { int n; printf("please input n:"); scanf("%d",&n); printf("a(n)=%d",a(n)); getch(); } 10. #include <stdio.h> main() { int a[3][4]={{1,2,3,4}, {9,8,7,6}, {-10,10,-5,2}}; int i,j,max,maxi,maxj; max=0; maxi=0; maxj=0; for(i=0;i<3;i++) for(j=0;j<3;j++) { if(max<a[i][j]) { max=a[i][j]; maxi=i; maxj=j; } } printf("maximum of the array is a[%d][%d]=%d",maxi,maxj,max); getch(); } 11. #include <stdio.h> main() { int i,n,num=0,sum=0; int a[100]; printf("please input the number of the
students n="); scanf("%d",&n); for(i=0;i<n;i++) { printf ("please input the NO.%d student's score",i+1); scanf("%d",&a[i]); if(a[i]>90)num++; sum+=a[i]; } printf("sum of the score is %d\nthe number of student whose score passed 90 is %d",sum,num); getch(); } 12. #include <stdio.h> main() { int f,g,x; printf("please input the value of x:") ; scanf("%d",&x); g=2*x+1; f=(g+1)/2; printf("G(x)=%d\n",g); printf("F(G(x))=%d\n",f); getch(); }