大一C语言编程题部分汇总.docx
输出众数:int main()int a10,b10=0; int i,j,max;for(i=0;i<10;i+)scanf("%d",&ai);for(i=0;i<10;i+)for(j=i;j<10;j+)if(ai=aj)bi+;max=b0;for(i=0;i<10;i+)if(bi>max)max=bi;if(max=1)printf("No");elsefor(i=0;i<10;i+)if(bi=max)printf("%d,%dn",ai,bi);return 0;l 平方数:#include<stdio.h>int main() int i,a,b; for(i=1000;i<=9999;i+) a=i/100; b=i%100; if(i=(a+b)*(a+b) printf("%dn",i); return 0;排序:由小到大#include<stdio.h>int main()int a10;int i,j,t;for(i=0;i<10;i+)scanf("%d",&ai);for(j=0;j<9;j+)for(i=0;i<9-j;i+)if(ai>ai+1)t=ai;ai=ai+1;ai+1=t;for(i=0;i<9;i+)printf("%dn",ai);printf("%d",a9);return 0;# int a11; int n,i,j; for(i=0;i<10;i+)scanf("%d",&ai); scanf("%d",&n);if(n>a9) a10=n;else for(i=0;i<9;i+) if(ai>n) for(j=9;j>=i;j-) aj+1=aj; ai=n; break;for(i=0;i<10;i+) printf("%d ",ai);printf("%d",a10);return 0;总平均成绩,各科平均成绩:#include<stdio.h>int main() int a35; int i,j; float sum3=0,0,0,total=0; for(i=0;i<3;i+) for(j=0;j<5;j+) scanf("%d",&aij); sumi+=aij; for(i=0;i<3;i+)for(j=0;j<5;j+)total+=aij; for(i=0;i<2;i+) printf("%.2f ",sumi/5); printf("%.2f",sumi/5); printf("n"); printf("%.2fn",total/15); return 0;*/找出最小数,输出其下标:/*#include<stdio.h>int main() int i,j,row=0,colum=0,min; int a34; for (i=0;i<3;i+) for(j=0;j<4;j+) scanf("%d",&aij); min=a00; for (i=0;i<3;i+) for(j=0;j<4;j+) if(aij<min) min=aij; row=i; colum=j; printf("min=%dn%d,%d",min,row,colum);return 0;*/*/求平均值:#include<stdio.h>float avernum(int a20) int i; float sum=0,aver;for(i=0;i<20;i+) sum=sum+ai; aver=sum/20.00; return(aver);int main() int a20,i; float x; for(i=0;i<20;i+) scanf("%d",&ai); x=avernum(a); printf("%f",x); return 0;编写一个函数fun,函数的功能是:判断一个整数是否既是5又是7的整倍数。若是,输出yes,否则输出no。在主函数中输入任意一个正整数,调用fun函数,输出该数对应的结果。主函数形式如下: int main() int n; scanf("%d",&n); fun(n); return 0; 要求:(1)本题main函数已在后台给出,不需要再写了,但需要给出合适的头文件。 (2)给出fun函数 #include<stdio.h> void fun(int x) if(x%5=0&&x%7=0) printf("yes"); else printf("no");int main() int n; scanf("%d",&n); fun(n); return 0;#include<stdio.h>int fac(int n) if(n=1|n=2)return 1;else return fac(n-1)+fac(n-2);int main()int i,n;scanf("%d",&n);for(i=1;i<=n;i+)if(i%5=0)printf("%dn",fac(i);elseprintf("%d ",fac(i);return 0; 将数组a 的数据逆序复制到数组b中,并输出数组b的值#include<stdio.h>int main()int i,*p;int a10,b10;for(i=0;i<10;i+)scanf("%d",&a);p=a;bi=*p;printf("%d ",bi);return 0;结构体定义时间结构体,输入某一时刻的时间,输出下一秒的时间#include<stdio.h>int main()struct Timeint h;int m;int s;t1,t2;scanf("%d:%d:%d",&t1.h,&t1.m,&t1.s);t2.s=t1.s+1;t2.m=t1.m;t2.h=t1.h;if(t2.s=60)t2.m=t1.m+1;t2.s=0;if(t2.m=60)t2.h=t1.h+1;t2.m=0;if(t2.h=24)t2.h=0;printf("%d:%d:%d",t2.h,t2.m,t2.s);return 0;#include<stdio.h>int main()struct Stuint num;char name20;float score3;struct Stu s5;int i,j;int k=0;k必须要赋初值float max;float sum5=0,sum13=0;for(i=0;i<5;i+)scanf("%d%s",&si.num,si.name);scanf("%f%f%f",&si.score0,&si.score1,&si.score2);max=s0.score0+s0.score1+s0.score2;for(i=0;i<5;i+)sumi=si.score0+si.score1+si.score2;for(i=0;i<5;i+)if(sumi>max)max=sumi;k=i;printf("%d %s ",sk.num,sk.name);printf("%.1f %.1f %.1fn",sk.score0,sk.score1,sk.score2);for(j=0;j<3;j+)for(i=0;i<5;i+)sum1j+=si.scorej;printf("%.1f %.1f %.1f",sum10/5,sum11/5,sum12/5);return 0;