《2022年c语言编程题.docx》由会员分享,可在线阅读,更多相关《2022年c语言编程题.docx(66页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精品学习资源1、求 1+2+3+.+100;循环答案#include void mainint i,sum=0; fori=1;i=100;i+ sum=sum+i; printf%d,sum;2、 求 1*2*3* .*10 ;循环答案void mainint i=0,j=1;for i=2;i=10;i+j*=i;printf%d,j; return 0;欢迎下载精品学习资源3、 输入三个数字,输出他们的最大值;if 答案#include void mainint a,b,c,d; scanf%d,%d,%d,&a,&b,&c; d=maxa,b,c;printfmax=%d,d;getc
2、h;/*暂停看运行结果 */int maxint x,int y,int zint u; ifx=y&x=z u=x;else ify=x&y=z u=y;else u=z;returnu;4. 用起泡法对十个数据排序数组实现答案#include欢迎下载精品学习资源main int i,j,t;static int a10=5,7,4,2,3,6,1,0,9,8;forj=0;j9;j+fori=0;ia t=a;a=a;a=t ;fori=0;i10;i+ printf%2d,a;5、输入十个数字,逆序输出;数组实现答案#include mainint a10,i=0; fori=0;i=0
3、;i-欢迎下载精品学习资源printf%f,a;6 输入两个数,交换他们的值并输出; 元素交换 答案#include int main int m,n,temp; scanf%d%d,&m,&n; if mntemp=m; m=n; n=temp;printf%d,m;return 0;7. 输出 9*9 乘法表;双层循环 答案#include void main欢迎下载精品学习资源int i=1;fori; i=9; i+int j=1; forj;j=i;j+printf%d*%d=%d , i, j, i*j;printfn;8. 输入一行字符,将全部的小写字母转换成大写字母, 大写字母
4、转换成小写字母,其余字符不变;输出转变 后的这行字符;答案#include stdio.h void mainchar an; int i;scanf%s,a;欢迎下载精品学习资源printf大写为: ; fori=0;i=n;i+ifa=a a=a-32;printf%c,a;printfn小写为: ; fori=0;i=65&c=97&c=48&c=100&x1000a=0.01*x;b=10*0.01*x-a;c=x-100*a-10*b; ifx=powa,3+powb,3+powc,3 printf%5d,x;x+;6.7mainint m,i,j,s; form=6;m10000;
5、m+s=1;fori=2;im;i+ ifm%i=0 s=s+i; ifm-s=0欢迎下载精品学习资源printf%5d its fastors are 1 ,m;forj=2;jm;j+ ifm%j=0printf%d ,j;printfn;或mainint m,i,j,s; form=6;m1000;m+s=m-1;fori=2;im;i+ ifm%i=0 s=s-i; ifs=0printf%5d its fastors are 1 ,m;forj=2;jm;j+ ifm%j=0printf%d ,j;printfn;6.8mainint i=1,n;double t,x=1,y=2,s
6、,sum=0; scanf%ld,&n;欢迎下载精品学习资源whilei=ns=y/x;sum=sum+s;t=y;y=y+x;x=t;i+; printf%fn,sum;11,P128例 6.10 译码#includevoid mainchar c; whilec=getchar.=nc=c+4; ifcZ+4|cz c=c-26;printf%c,c;printfn;12,P1115.55.6 switch 5.5#include 欢迎下载精品学习资源mainint x,y;printf输入 x:;scanf%d,&x; ifx1 y=x;printfx=%3d, y=x=%dn,x,y;
7、else if x10 y=2*x-1;printfx=%3d, y=2*x-1=%dn,x,y;else y=3*x-11;printfx=%3d, y=3*x-11=%dn,x,y;5.6#include main float score;欢迎下载精品学习资源char grade; case 2:printf请输入同学成果: ;scanf%f,&score; whilescore100|score0 printfn输入有误 , 请重新输入: ;scanf%f,&score;switchintscore/10 case 10:case 9: grade= A;break; case 8: g
8、rade= B;break; case 7: grade= C;break; case 6: grade= D;break; case 5:case 4:case 3:case 1:case 0: grade=E;printf成果是 %5.1f ,相应的等级是 %c;n,score,grade;欢迎下载精品学习资源13,P108例 5.5 一元二次方程求根 例 5.6求闰年5.5#include void mainint year,leap; scanf%d,&year; ifyear%4=0ifyear%100=0ifyear%400=0 leap=1;else leap=0;else le
9、ap=1;欢迎下载精品学习资源else leap=0; ifleapprintf%d is,year; elseprintf%d is not,year;printfa leap year.n5.614,P31例 2.17例 2.182.17输出 50 个同学中成果高于 80 分者的学号和成果2.18输出 2000 2500 年每一年是否闰年#includevoid mainint year; year=2000;go: ifyear%4 = 0&year%100 .= 0 | year%400 = 0printf%d is run欢迎下载精品学习资源nian,year;ifyear2500
10、goto end;欢迎下载精品学习资源goto go;end:getch;1、求 1+2+3+ .+100 ;循环答案#include void mainint i,sum=0; fori=1;i=100;i+ sum=sum+i; printf%d,sum;2、 求 1*2*3* .*10 ;循环答案void main欢迎下载精品学习资源int i=0,j=1;for i=2;i=10;i+j*=i;printf%d,j; return 0;3、 输入三个数字,输出他们的最大值;if 答案#include void mainint a,b,c,d; scanf%d,%d,%d,&a,&b,&
11、c; d=maxa,b,c;printfmax=%d,d;getch;/*暂停看运行结果 */int maxint x,int y,int zint u; ifx=y&x=z u=x;欢迎下载精品学习资源else ify=x&y=z u=y;else u=z;returnu;4. 用起泡法对十个数据排序数组实现答案#include main int i,j,t;static int a10=5,7,4,2,3,6,1,0,9,8;forj=0;j9;j+fori=0;ia t=a;a=a;a=t ;fori=0;i10;i+ printf%2d,a;5、输入十个数字,逆序输出;数组实现欢迎下载
12、精品学习资源答案#include mainint a10,i=0; fori=0;i=0;i-printf%f,a;6 输入两个数,交换他们的值并输出; 元素交换 答案#include int main int m,n,temp; scanf%d%d,&m,&n; if mntemp=m; m=n; n=temp;欢迎下载精品学习资源printf%d,m;return 0;7. 输出 9*9 乘法表;双层循环 答案#include void mainint i=1;fori; i=9; i+int j=1; forj;j=i;j+printf%d*%d=%d , i, j, i*j;print
13、fn;8. 输入一行字符,将全部的小写字母转换成大写字母, 大写字母转换成小写字母,其余字符不变;输出转变欢迎下载精品学习资源后的这行字符;答案#include stdio.h void mainchar an; int i;scanf%s,a;printf大写为: ; fori=0;i=n;i+ifa=a a=a-32;printf%c,a;printfn小写为: ; fori=0;i=65&c=97&c=48&c=100&x1000a=0.01*x;b=10*0.01*x-a;c=x-100*a-10*b; ifx=powa,3+powb,3+powc,3 printf%5d,x;x+;欢
14、迎下载精品学习资源6.7mainint m,i,j,s; form=6;m10000;m+s=1;fori=2;im;i+ ifm%i=0 s=s+i; ifm-s=0printf%5d its fastors are 1,m;forj=2;jm;j+ ifm%j=0printf%d ,j;printfn;或mainint m,i,j,s; form=6;m1000;m+s=m-1;fori=2;im;i+ ifm%i=0 s=s-i; ifs=0printf%5d its fastors are 1欢迎下载精品学习资源,m;forj=2;jm;j+ ifm%j=0printf%d ,j;pr
15、intfn;6.8mainint i=1,n;double t,x=1,y=2,s,sum=0; scanf%ld,&n;whilei=ns=y/x;sum=sum+s;t=y;y=y+x;x=t;i+; printf%fn,sum;11,P128例 6.10 译码#includevoid mainchar c; whilec=getchar.=nc=c+4; ifcZ+4|cz c=c-26;欢迎下载精品学习资源printf%c,c;printfn;12,P1115.55.6 switch 5.5#include mainint x,y;printf输入 x:;scanf%d,&x; ifx
16、1 y=x;printfx=%3d, y=x=%dn,x,y;else if x10 y=2*x-1;printfx=%3d, y=2*x-1=%dn,x,y;else欢迎下载精品学习资源 y=3*x-11;printfx=%3d, y=3*x-11=%dn,x,y;5.6#include main float score; char grade; case 2:printf请输入同学成果: ;scanf%f,&score; whilescore100|score0 printfn输入有误 , 请重新输入: ;scanf%f,&score;switchintscore/10 case 10:c
17、ase 9: grade= A;break; case 8: grade= B;break; case 7: grade= C;break; case 6: grade= D;break;欢迎下载精品学习资源case 5:case 4:case 3:case 1:case 0: grade=E;printf成果是 %5.1f ,相应的等级是 %c;n,score,grade;13,P108例 5.5 一元二次方程求根 例 5.6求闰年5.5#include void mainint year,leap; scanf%d,&year; ifyear%4=0ifyear%100=0欢迎下载精品学习
18、资源ifyear%400=0 leap=1;else leap=0;else leap=1;else leap=0; ifleapprintf%d is,year;elseprintf%d is not,year; printfa leap year.n5.614,P31例 2.17例 2.182.17输出 50 个同学中成果高于 80 分者的学号和成果2.18输出 2000 2500 年每一年是否闰年欢迎下载精品学习资源#includevoid mainint year; year=2000;go: ifyear%4 = 0&year%100 .=0 | year%400 = 0欢迎下载精品
19、学习资源nian,year;printf%d is runifyear2500 goto end;欢迎下载精品学习资源goto go;end:getch;1、求 1+2+3+ .+100 ;循环答案#include void mainint i,sum=0;欢迎下载精品学习资源fori=1;i=100;i+ sum=sum+i; printf%d,sum;2、 求 1*2*3* .*10 ;循环答案void mainint i=0,j=1;for i=2;i=10;i+j*=i;printf%d,j; return 0;3、 输入三个数字,输出他们的最大值;if 答案#include void
20、 mainint a,b,c,d;scanf%d,%d,%d,&a,&b,&c;欢迎下载精品学习资源d=maxa,b,c;printfmax=%d,d;getch;/*暂停看运行结果 */int maxint x,int y,int zint u; ifx=y&x=z u=x;else ify=x&y=zu=y; else u=z;returnu;4. 用起泡法对十个数据排序数组实现答案#include main int i,j,t;static int a10=5,7,4,2,3,6,1,0,9,8;forj=0;j9;j+fori=0;ia欢迎下载精品学习资源 t=a;a=a;a=t ;f
21、ori=0;i10;i+ printf%2d,a;5、输入十个数字,逆序输出;数组实现答案#include mainint a10,i=0; fori=0;i=0;i-printf%f,a;6 输入两个数,交换他们的值并输出; 元素交换 答案#include int main 欢迎下载精品学习资源int m,n,temp;scanf%d%d,&m,&n; if mntemp=m; m=n; n=temp;printf%d,m;return 0;7. 输出 9*9 乘法表;双层循环 答案#include void mainint i=1;fori; i=9; i+int j=1; forj;j=
22、i;j+欢迎下载精品学习资源printf%d*%d=%d , i, j, i*j;printfn;8. 输入一行字符,将全部的小写字母转换成大写字母, 大写字母转换成小写字母,其余字符不变;输出转变 后的这行字符;答案#include stdio.h void mainchar an; int i;scanf%s,a;printf大写为: ; fori=0;i=n;i+ifa=a a=a-32;printf%c,a;欢迎下载精品学习资源printfn小写为: ; fori=0;i=65&c=97&c=48&c=100&x1000a=0.01*x;b=10*0.01*x-a;c=x-100*a-
23、10*b; ifx=powa,3+powb,3+powc,3 printf%5d,x;x+;6.7mainint m,i,j,s; form=6;m10000;m+s=1;fori=2;im;i+ ifm%i=0 s=s+i; ifm-s=0printf%5d its fastors are 1,m;forj=2;jm;j+ ifm%j=0printf%d ,j;printfn;或欢迎下载精品学习资源mainint m,i,j,s; form=6;m1000;m+s=m-1;fori=2;im;i+ ifm%i=0 s=s-i; ifs=0printf%5d its fastors are 1
24、 ,m;forj=2;jm;j+ ifm%j=0printf%d ,j;printfn;6.8mainint i=1,n;double t,x=1,y=2,s,sum=0; scanf%ld,&n;whilei=ns=y/x;sum=sum+s;t=y;y=y+x;x=t;i+; printf%fn,sum;11,P128例 6.10 译码#include欢迎下载精品学习资源void mainchar c; whilec=getchar.=nc=c+4; ifcZ+4|cz c=c-26;printf%c,c;printfn;12,P1115.55.6 switch 5.5#include m
25、ainint x,y;printf输入 x:;scanf%d,&x; ifx1欢迎下载精品学习资源 y=x;printfx=%3d, y=x=%dn,x,y;else if x10 y=2*x-1;printfx=%3d, y=2*x-1=%dn,x,y;else y=3*x-11;printfx=%3d, y=3*x-11=%dn,x,y;5.6#include main float score;char grade; case 2:printf请输入同学成果: ;scanf%f,&score; whilescore100|score0 printfn输入有误 , 请重新输入: ;欢迎下载精
26、品学习资源scanf%f,&score;switchintscore/10 case 10:case 9: grade=A;brea k; case 8: grade=B;break; case 7: grade=C;break; case 6: grade=D;break; case 5:case 4:case 3:case 1:case 0: grade=E;printf成果是 %5.1f ,相应的等级是 %c;n,score,grade;13,P108例 5.5 一元二次方程求根 例 5.6求闰年5.5#include欢迎下载精品学习资源void mainint year,leap; s
27、canf%d,&year; ifyear%4=0ifyear%100=0ifyear%400=0 leap=1;elseleap=0;else leap=1;else leap=0; ifleapprintf%d is,year; elseprintf%d is not,year;欢迎下载精品学习资源printfa leap year.n5.614,P31例 2.17例 2.182.17输出 50 个同学中成果高于 80 分者的学号和成果2.18输出 2000 2500 年每一年是否闰年#includevoid mainint year; year=2000;go: ifyear%4 = 0&year%100 .= 0 | year%400 = 0欢迎下载精品学习资源nian,year;printf%d is runifyear2500 goto end;欢迎下载精品学习资源goto go;欢迎下载精品学习资源end:getch;欢迎下载