1、判断一个三位数的个位和百位之和等于十位。
#include<stdio.h>int main(int argc, char* argv[]){int sum,a,b,c;printf("请输入一个三位数\n");scanf("%d",&sum);a=sum%10;c=sum/10%10;b=sum/100;if(c==a+b)printf("yes\n");elseprintf("no\n");return 0;}2、假如我国国民生产总值的年增长率为10%,计算10年后我国国民生产总值与现在相比增长多少百分比?计算公式:P=(1+r)的n次方,r为年增长率;n为年数;P为与现在相比的百分比。
#include <stdio.h>#include<math.h>int main(int argc, char* argv[]){int n;scanf("%d",&n);float r,p;r=0.1;p=pow((1+r),n);printf("p=%f\n",p);return 0;}3、输入5个字符密码,密码规律是用原来的字母后面第四个字母代替原来的字母。
#include<stdio.h>int main(int argc, char* argv[]){char c1,c2,c3,c4,c5;printf ("请输入5个字符\n");scanf("%c%c%c%c%c",&c1,&c2,&c3,&c4,&c5);c1=c1+4;c2=c2+4;c3=c3+4;c4=c4+4;c5=c5+4;printf("%c%c%c%c%c\n",c1,c2,c3,c4,c5);return 0;}4、#include<stdio.h>int main(int argc, char* argv[]){int m=12,n=34;printf("%d\n%d\n",m++,++n);printf("%d\n%d\n",n++,++m);return 0;}m=12,n=35;m=35,n=145、#include<stdio.h>int main(int argc, char* argv[]){char a='1',b='2';printf("%c\n",b++);printf("%d\n",b-a);return 0;}a=2,b=26、#include <stdio.h>int main(int argc, char* argv[]){int x,a;x=a=2*3,a*4,a+5;printf("x=%d\n,a=%d\n",x,a);return 0;}x=6,a=67、输入一个字符,输出变为小写,否则输入错误。
#include<stdio.h>int main(int argc, char* argv[]){char a;printf("请输入一个字符\n");scanf("%c",&a);if((a<='Z'&&a>='A')||a<='z'&&a>='a'){a=a+32;printf("%c\n",a);}elseprintf("输入错误\n");return 0;}8、输入一个华氏温度,要求输出摄氏温度。
公式为c=5/9(F-32)输出要有文字说明个,取两位小数。
#include<stdio.h>int main(int argc, char* argv[]){float F,c;printf("请输入一个华氏温度\n");scanf("%f",&F);c=5.0/9.0*(F-32);Printf("%.2f\n",c);return 0;}9、输入一个字符,输出来的是ASCII代码值#include<stdio.h>int main(int argc, char* argv[]){char a;printf("输入一个字符\n");scanf("%c",&a);printf("%d\n",a);return 0;}10、{int a=123;float b=123.1234567;double c=12345678.1234567;char ch='f';printf("a=%d,%8.5d,%08d,%o,%#x\n",a,a,a,a,a);printf("b=%f,%-10.3f,%e,%g\n",b,b,b,b);printf("c=%f,%8.4f,%g\n",c,c,c);printf("ch=%c,%8c\n",ch,ch);printf("%s,%.4s\n","abcdef","abcdef");return 0;}11、从键盘输入一个大写字母,要求改用小写字母输出;(1)一般做法:#include<stdio.h>int main(int argc, char* argv[]){char a;printf("请输入一个字母\n");scanf("%c",&a);a=a+32;printf("%c\n",a);return 0;}(2)用getchar做:#include<stdio.h>int main(int argc, char* argv[]){putchar(getchar()+32);putchar('\n');return 0;}(3)简单做法:#include<stdio.h>int main(int argc, char* argv[]){printf("%c\n",getchar()+32);return 0;}12、实现输入两个数,从大到小输出#include<stdio.h>int main(int argc, char* argv[]){int a,b,t;printf("请输入两个数\n");scanf("%d%d",&a,&b);if(a<b){t=a;a=b;b=t;}printf("%d%d",a,b);return 0;}13、X、Y有这样的关系:Y=-1(X<0);Y=0(X=0);Y=1(X>0) #include<stdio.h>int main(int argc, char* argv[]){int x,y;printf("输入一个x值\n");scanf("%d",&x);if(x<0) y=-1;elseif(x==0) y=0;elsey=1;printf("y=%d\n",y);return 0;}14、输入a,b,c三个数,输出最大数。
#include<stdio.h>int main(int argc, char* argv[]){float a,b,c;scanf ("%f%f%f",&a,&b,&c);if (a>b){if(a>c)printf("%f",a);elseprintf("%f",c);}else{if(b>c)printf("%f",b);elseprintf("%f",c);}return 0;}15、输一个字符,判别他是否大写字母,如果是,将他转换成小写,如果不是,不转换,然后输出最后的字符。
#include<stdio.h>int main(int argc, char* argv[]){char a;printf("输入一个字符\n");scanf("%c",&a);if (a>='A'&&a<='Z'){printf("%c\n",a=a+32);}elseprintf("%c\n",a);return 0;}16、求n!#include<stdio.h>int main(int argc, char* argv[]){int n,sum,a;scanf("%d",&n);a=1,sum=1;while (a<=n){sum=sum*a;a++;}printf("%d\n",sum);return 0;}17、用条件运算符编写第15题#include<stdio.h>int main(int argc, char* argv[]){char a;printf("输入一个字符\n");scanf("%c",&a);a>='A'&&a<='Z'?a=a+32:a;printf("%c\n",a);return 0;}18、求1+2+3+....+100#include<stdio.h>int main(int argc, char* argv[]){int sum,a;a=1;sum=0;while(a<=100){sum=sum+a;a++;}printf("%d",sum);return 0;}19、求1+2+3+….+n#include<stdio.h>int main(int argc, char* argv[]){int sum,a,n;a=1;sum=0;scanf(“%d”,&n);while(a<=n){sum=sum+a;a++;}printf("%d",sum);return 0;}20、求1!+2!+3!+....+n!#include<stdio.h>int main(int argc, char* argv[]){int n,a,ch,sum;a=1,ch=1;sum=0;scanf("%d",&n);while (a<=n){ch=ch*a;a++;sum=sum+ch;}printf("%d\n",sum);return 0;}21、有一数m,判断他是否是质数?#include<stdio.h>#include<math.h>int main(int argc, char* argv[]){int m,i,k;printf("请输入一个数\n");scanf("%d",&m);k=(int)sqrt(m); *对m求平方根,再取整*for (i=2;i<=k;i++)if (m%i==0) break;if(i>k) printf("true\n");else printf("false\n");return 0;}22、用do...while语句求n!#include<stdio.h>int main(int argc, char* argv[]) {int i,n,sum;scanf("%d",&n);i=1;sum=1;do{sum=sum*i;i++;}while (i<=n);printf("%d",sum);return 0;}23、用for语句求n!#include<stdio.h>int main(int argc, char* argv[]) {int i,sum,n;scanf("%d",&n);sum=1;for (i=1;i<=n;i++)sum=sum*i;printf("%d\n",sum);return 0;}24、求两个整数m,n的最大公约数#include<stdio.h>int main(int argc, char* argv[]) {int m,n,sum;scanf(“%d%d”,&m,&n);do{sum=m%n;m=n;n=sum;}while(sum!=0);printf("%d",m);return 0;}25、求100以内的质数#include <stdio.h>int main(int argc, char* argv[]){int i, j;for(i=2; i<=100; i++){for(j=2; j<i&&i%j!=0; j++);if(j==i) printf("%d ", i);}printf("\n");return 0;}26、9*9乘法表#include<stdio.h>int main(int argc, char* argv[]){int a,b,c;for(a=1;a<=9;a++){for(b=1;b<=a;b++){c=a*b;printf("%d*%d=%d\t",b,a,c);}printf("\n");}return 0;}27、募集慈善基金10000元,每输入一个人是捐款数后,计算机就输出当时捐款总和。