1、C语言上机题整理(孙玲出品)/*输入任一年份,判断是否为闰年。*/#include void main(void) int year,leap;scanf(“%d“,if(year%400=0) leap=1;else if(year%4=0)else leap=0;if(leap!=0)printf(“%d is a leap year.n“,year);elseprintf(“%d is not a leap year.n“,year);/=/*s1=2a/b;s2=b/a a=bs1=b/a;s2=100b avoid main(void)float a,b,s1,s2;scanf(“%
2、f,%f“,if(a=b)s1=2*a/b;s2=b/a;elses1=b/a;s2=100*b;printf(“%f,%f“,s1,s2);/=/*输入一个整数,将其数值按小于10,1099,100999和1000以上分类并显示。例如:输入732时,显示“732 is 100 to 999“*/#include void main(void)int x;scanf(“%d“,if(xvoid main(void)int i,s=1;for(i=1;ivoid main(void)int i,n=0;for(i=1;i#include void main()int i;double s,t,m
3、;for(i=1,m=0.0;ivoid main(void)int a,b,c,max;scanf(“%d,%d,%d“,if(ab)max=a;elsemax=b;if(maxvoid main()int a,b,c,max;scanf(“%d,%d,%d“,max=(ab)?a:b;max=(max#include void main(void)double s,a,b;a=30*3.14159/180;b=60*3.14159/180;s=sin(a)+sin(b)+cos(a)+cos(b);printf(“s=%fn“,s);/=/*求一个任意的圆的面积和周长。*/#define
4、PI 3.14159#include void main(void)double r,area,s;scanf(“%f“,area=PI*r*r;s=2*PI*r;printf(“area=%7.2fns=%7.2fn“,area,s);/=/*从键盘输入一个华氏温度,转换成对应的摄氏温度。*/#include void main(void)float F,C;scanf(“%f“,C=(F-32)*5/9;printf(“C=%fn“,C);/= /* 输入一个三位数,依次输出该数的个位,十位,百位数字。*/#include void main(void)int x,a,b,c;scanf(
5、“%d“,a=x/100;b=(x-100*a)/10;c=(x-100*a)%10;printf(“%d,%d,%dn“,a,b,c);/= /* 从键盘任意输入一个小写字母,将其转换成对应的大写字母和10进制数。*/#include void main(void)char c1;c1=getchar();c1=c1-32;putchar(c1);printf(“%dn“,c1);/= /* 求s=1!+2!+3!+.+10!*/#include void main(void)int i;float s,t;t=1;s=0;for(i=1;ivoid main(void)int n,i;fl
6、oat s,a=0.0,b=0.0;printf(“n=?“);scanf(“%d“,for(i=1;i0)a+=s;elseb+=s;printf(“正数之和为%fn“,a);printf(“负数之和为%fn“,b);/= /* 编程输出100以内能被3整除,或能被4整除,且个位数为6的所有正整数。*/#include void main(void)int i;for(i=1;ivoid main(void)int i,j;for(i=1;i#include void main(void)int aN,i,j,iTemp;for(i=0;iaj)iTemp=ai;ai=aj;aj=iTemp
7、; for(i=0;ivoid main(void)int x100,i,imax,imin,a,b,n;scanf(“%d“,for(i=0;iimax)imax=xi;a=i;if(xivoid main(void)float fScore46,aver=0,f;int i,iCount=0,m;scanf(“%d“,for(i=0;iaver)iCount+;f=(float)iCount*100/m;printf(“iCount=%dn“,iCount);printf(“%f%n“,f);/= /* 生成三 (下三 为0)例如:1 2 3 40 5 6 70 0 9 100 0 0 1
8、1*/#include #include void main(void)int a44,i,j;for(i=0;i#include void main(void)int a44,i,j,s=0;for(i=0;ivoid main(void)int i,j,a66=0;for(i=0;i#include void main(void)char str80;int i,j,k;gets(str);j=strlen(str);for(i=0;i#include void main(void)int i,a,b,c,d;char str80;gets(str);a=0;b=0;c=0;d=0;for
9、(i=0;stri!=0;i+)if(stri=aint i,j=0,k;gets(str);k=strlen(str);for(i=0;i#include void main(void)char s80,t80;int i,j=0,k;gets(s);k=strlen(s);gets(t);for(i=k;idouble md(int);void main()int i,n;double a=0.0;scanf(“%d“,for(i=1;iint fun(int b);void main()int i,a10;for(i=0;ibj)iTemp=bi;bi=bj;bj=iTemp;retur
10、n bi;/= /* 编写一数求N!的“和s=1!+2!+3!+.+n! */#include int fac(int);void main()int i,n;long sum=0l;scanf(“%d“,for(i=1;iint md(int,int);void main()int a,b,m;scanf(“%d,%d“,m=md(a,b);printf(“最大数:%dn“,m);int md(int x,int y)int t;if(xint cm(char str,int);void main()char str80;char c=*;gets(str);cm(str,c);puts(s
11、tr);int cm(char str,int c)int i,j;for(i=0,j=0;ivoid main()char a80,b40,*p,*q;gets(a);gets(b);p=a;q=b;while(*p)p+;while(*q)*p=*q;p+;q+;puts(a);/= /* fifl 求全 同的 分,最 分,最分。*/#include void as(float f,int n);void im(float f,int n);void main()float f46,*q,av=0,max,min;int i,n;q=max=min=f0;scanf(“%d“,for(i=
12、0;imax)max=*p;if(*p#include void main()int a54,i,j,max;for(i=0;i#include void main()int a54,i,j,*p,max;p=a0;for(i=0;i#include void main()int a54,i,j,(*p)4,max;p=a;for(i=0;i#include void main()int a54,i,j,max;int *p5=a0,a1,a2,a3,a4;for(i=0;i5;i+)for(j=0;j4;j+)aij=rand()%100;for(i=0;i5;i+)for(j=0;j4;j+)printf(“%4d“,aij);printf(“n“);max=a00;for(i=0;i5;i+)for(j=0;j4;j+)if(max*(*(p+i)+j)max=*(*(p+i)+j);printf(“max=%dn“,max);/=