您好,欢迎访问三七文档
当前位置:首页 > 机械/制造/汽车 > 制造加工工艺 > C语言操作题常考编程题库
C语言编程题覆盖到的算法:1、个人所得税计算;2、求一组数的正、负数(或奇、偶数)的个数和平均值;3、二维数组主、次对角线之和;4、求素数(用函数实现);5、级数有限项求和问题;6、两个一维数组相加(用函数实现);7、求最大、最小值;8、判断闰年(用函数实现);9、求水仙花数;10、百钱百鸡;11、求最大公约数、最小公倍数。12、求回文数;13、排序;14、二维数组的转置;15、递归函数求阶乘;16、求斐波那契数列;17、求和:a+aa+aaa+aaaa+....;18、求符合条件的整数(如:是某个二位数的平方,个位、十位、百位数各不相同等);(包括素数,回文,完数,等等)19、字符串加密;20、统计字符串中字母和数字的个数;/*1.个人所得税计算,以实验指导P24T5为标准*/#includestdio.hvoidmain(){inti,n;doublea,b,c;n=i/400;printf(pleaseinputincome:\n);scanf(%d,&i);a=(i-800)*0.05,b=20+(i-1200)*0.08,c=84+(i-2000)*0.2;switch(n){case0:case1:printf(不需缴税\n);break;case2:printf(需交纳%lf元\n,a);break;case3:case4:printf(需交纳%lf元\n,b);break;default:printf(需交纳%lf元\n,c);break;}}/*2.求一组数的奇数个数,偶数个数和平均值#includestdio.h#defineN10voidmain(){inta[N];inti,m=0,n=0,sum=0;doubleaverage;printf(pleaseinput10numbers:\n);for(i=0;iN;i++){scanf(%d,&a[i]);if(a[i]%2==0)m++;elsen++;sum+=a[i];}average=(double)sum/N;printf(wehave%doddsand%devens\n,n,m);printf(average=%lf\n,average);}*//*2'.求一组数的正数个数和负数个数与平均值*/#includestdio.h#defineN10voidmain(){inta[N];inti,m=0,n=0,sum=0;doubleaverage;printf(pleaseinput10numbers:\n);for(i=0;iN;i++){scanf(%d,&a[i]);if(a[i]0)m++;elsen++;sum+=a[i];}average=(double)sum/N;printf(wehave%dpositivenumbersand%dnagetivenumbers\n,m,n);printf(theaverage=%lf,average);}/*3.求二维数组的主次对角线之和*/#includestdio.h#defineM5#defineN5voidmain(){inta[M][N];inti,j,sum1=0,sum2=0;printf(pleaseinputthematrix:\n);for(i=0;iM;i++){for(j=0;jN;j++){scanf(%d,&a[i][j]);}}for(i=0,j=0;iM;i++,j++){sum1+=a[i][j];}for(i=0,j=N-1;iM;i++,j--){sum2+=a[i][j];}printf(主对角线和为%d\n,sum1);printf(次对角线和为%d\n,sum2);}/*4.调用函数判断素数*/#includestdio.h#includemath.hintisPrime(intn){inti;for(i=1;isqrt(n);i++){if(n%i==0)return0;}return1;}voidmain(){intn,i;printf(pleaseinputanumber\n);scanf(%d,&n);i=isPrime(n);if(i)printf(%disaprime\n,n);elseprintf(%disnotaprime\n,n);}//5.级数有限项求和(以格里高利公式求π为例)//#includestdio.h#includemath.hvoidmain(){intn=1;doublep=0,t,pi;t=1/(pow((-1),(n+1))*2*(n-1));while(fabs(t)=1e-6){pi+=t;n++;}pi=4*p;printf(%lf,pi);}//6.两个一维数组相加///*#includestdio.h#defineN5voidmain(){inta[N],b[N],c[N];inti;printf(pleaseinputthefirstarraya[N]:\n);for(i=0;iN;i++){scanf(%d,&a[i]);}printf(pleaseinputthesecondarrayb[N]:\n);for(i=0;iN;i++){scanf(%d,&b[i]);}for(i=0;iN;i++){c[i]=a[i]+b[i];}printf(thesumis:\n);for(i=0;iN;i++)printf(%d\t,c[i]);}*///6.1调用函数实现//#includestdio.h#defineN5intf(inta,intb){intsum;sum=a+b;returnsum;}voidmain(){inta[N],b[N],c[N];inti;printf(pleaseinputthefirstarraya[N]:\n);for(i=0;iN;i++){scanf(%d,&a[i]);}printf(pleaseinputthesecondarrayb[N]:\n);for(i=0;iN;i++){scanf(%d,&b[i]);}for(i=0;iN;i++){c[i]=f(a[i],b[i]);}printf(thesumis:\n);for(i=0;iN;i++)printf(%d\t,c[i]);}/*7.求一组数的最大最小值*//*#includestdio.hvoidmain(){inti,max,min;inta[10];printf(pleaseinputtennumbers\n);for(i=0;i10;i++){scanf(%d,&a[i]);}max=a[0];min=a[0];for(i=1;i10;i++){if(a[i]max){max=a[i];}if(a[i]min){min=a[i];}}printf(maxis%d,minis%d\n,max,min);}*//*随机数*/#includestdio.h#includestdlib.hvoidmain(){inti,max,min;inta[10];for(i=0;i10;i++){a[i]=rand()%90+10;printf(%d\t,a[i]);}max=a[0];min=a[0];for(i=1;i10;i++){if(a[i]max)max=a[i];if(a[i]min)min=a[i];}printf(max=%d\tmin=%d\n,max,min);}/*8.判断闰年*/#includestdio.hintf(intn){if(n%4==0&&n%100!=0||n%400==0)return1;elsereturn0;}voidmain(){intn;printf(pleaseinputyear:\n);scanf(%d,&n);if(f(n))printf(%d是闰年\n,n);elseprintf(%d不是闰年\n,n);}/*可能会有要输出某一范围内所有闰年,思想一样,用循环调用函数即可*//*9.判断水仙花数(运用循环)#includestdio.hvoidmain(){intn,a,b,c,m;printf(pleaseinputanumber:\n);scanf(%d,&n);a=n/100;b=n/10%10;c=n%10;m=a*a*a+b*b*b+c*c*c;if(m==n)printf(%disthenumberwewant\n,n);elseprintf(%disnotthenumber\n,n);}*//*9'.输出所有水仙花数(调用函数(书P108为循环做法))*/#includestdio.hintf(intn){inta,b,c,m;a=n/100;b=n/10%10;c=n%10;m=a*a*a+b*b*b+c*c*c;if(m==n)return1;elsereturn0;}voidmain(){inti,t;for(i=100;i1000;i++){t=f(i);if(t==1)printf(%d\t,i);}}//10.百钱买百鸡(题目见书P115)//#includestdio.hvoidmain(){inti,j,k;for(i=0;i=20;i++){for(j=0;j=33;j++){for(k=3;k=99;k+=3){if((i+j+k==100)&&(5*i+3*j+k/3==100))printf(公鸡%d只,母鸡%d只,小鸡%d只\n,i,j,k);}}}}/*11.求最大公约数和最小公倍数,函数实现*/#includestdio.hintf(intm,intn){inti=1,t;if(mn){t=m;m=n;n=t;}while((i=m%n)!=0){m=n;n=i;}returnn;}intg(intm,intn){inti,j;i=f(m,n);j=m*n/i;returnj;}voidmain(){intm,n,a,b;printf(pleaseinputtwonumbers:\n);scanf(%d%d,&m,&n);a=f(m,n);b=g(m,n);printf(最大公约数为%d\n,a);printf(最小公倍数为%d\n,b);}//12.1输出10-2000之间的回文数(循环)///*#includestdio.hvoidmain(){inti,j,k=0,a;printf(10-2000之间的回文数有:\n);for(i=10;i=2000;i++){a=i;j=0;while(a0){j=j*10+a%10;a/=10;}if(i==j){printf(%d\t,i);k++;if(k%5==0)printf(\n);}}printf(\n);}*///12.2输出10-2000之间的回文数(函数调用)///*#includestdio.hintf(intn){inti=0;while(n0){i=i*10+n%10;n/=10;}returni;}voidmain(){intn,k;printf(10-2000之间的回文数有:\n);for(n=10;n=2000;n++){if(n==f(n)){printf(%d\t,n);k++;if(k%5==0)printf(\n);}}printf(\n);}*///12.3判断回文数(循环)///*#includestdio.hvoidmain(){inti,a,j=0;printf(pleaseinputanumber:\n);scanf(%d,&i);a=i;while(a0){j=j*10+a%10;a/=10;}if(j==i)printf(%d是回文数\n,i);elseprintf(%d不是回文数\n,i);}*///12.4判断回文数(函数调用)//#inc
本文标题:C语言操作题常考编程题库
链接地址:https://www.777doc.com/doc-4495326 .html