1、C语言操作题常考编程题库C语言操作题常考编程题库C语言编程题覆盖到的算法:1、个人所得税计算;2、求一组数的正、负数(或奇、偶数)的个数和平均值;3、二维数组主、次对角线之和;4、求素数(用函数实现);5、级数有限项求和问题;6、两个一维数组相加(用函数实现);7、求最大、最小值;8、判断闰年(用函数实现);9、求水仙花数;10、百钱百鸡;11、求最大公约数、最小公倍数。12、求回文数;13、排序;14、二维数组的转置;15、递归函数求阶乘;16、求斐波那契数列;17、求和:a+aa+aaa+aaaa+.;18、求符合条件的整数(如:是某个二位数的平方,个位、十位、百位数各不相同等);(包括素
2、数,回文,完数,等等)19、字符串加密;20、统计字符串中字母和数字的个数;/*1.个人所得税计算,以实验指导P24T5为标准*/#includevoid main() int i,n; double a,b,c; n=i/400; printf(please input income:n); scanf(%d,&i); a=(i-800)*0.05,b=20+(i-1200)*0.08,c=84+(i-2000)*0.2; switch(n) case 0: case 1:printf(不需缴税n);break; case 2:printf(需交纳%lf元n,a);break; case 3
3、: case 4:printf(需交纳%lf元n,b);break; default:printf(需交纳%lf元n,c);break; /*2. 求一组数的奇数个数,偶数个数和平均值#include#define N 10void main() int aN; int i,m=0,n=0,sum=0; double average; printf(please input 10 numbers:n); for(i=0;iN;i+) scanf(%d,&ai); if(ai%2=0) m+; else n+; sum+=ai; average=(double)sum/N; printf(we
4、have %d odds and %d evensn,n,m); printf(average=%lfn,average);*/*2.求一组数的正数个数和负数个数与平均值*/#include#define N 10void main() int aN; int i,m=0,n=0,sum=0; double average; printf(please input 10 numbers:n); for(i=0;i0) m+; else n+; sum+=ai; average=(double)sum/N; printf(we have %d positive numbers and %d na
5、getive numbersn,m,n); printf(the average =%lf,average); /*3.求二维数组的主次对角线之和*/#include#define M 5 #define N 5void main() int aMN; int i,j,sum1=0,sum2=0; printf(please input the matrix:n); for(i=0;iM;i+) for(j=0;jN;j+) scanf(%d,&aij); for(i=0,j=0;iM;i+,j+) sum1+=aij; for(i=0,j=N-1;iM;i+,j-) sum2+=aij; p
6、rintf(主对角线和为%dn,sum1); printf(次对角线和为%dn,sum2);/*4.调用函数判断素数*/#include#includeint isPrime(int n) int i; for(i=1;isqrt(n);i+) if(n%i=0) return 0; return 1;void main() int n,i; printf(please input a numbern); scanf(%d,&n); i=isPrime(n); if(i) printf(%d is a primen,n); else printf(%d is not a primen,n);/
7、5.级数有限项求和(以格里高利公式求为例)/#include#includevoid main() int n=1; double p=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.两个一维数组相加/*#include#define N 5void main() int aN,bN,cN; int i; printf(please input the first array aN:n); for(i=0;iN;i+) scanf(%d,&ai); prin
8、tf(please input the second array bN:n); for(i=0;iN;i+) scanf(%d,&bi); for(i=0;iN;i+) ci=ai+bi; printf(the sum is:n); for(i=0;iN;i+) printf(%dt,ci);*/6.1调用函数实现/#include#define N 5int f(int a,int b) int sum; sum=a+b; return sum;void main() int aN,bN,cN; int i; printf(please input the first array aN:n)
9、; for(i=0;iN;i+) scanf(%d,&ai); printf(please input the second array bN:n); for(i=0;iN;i+) scanf(%d,&bi); for(i=0;iN;i+) ci=f(ai,bi); printf(the sum is:n); for(i=0;iN;i+) printf(%dt,ci);/*7.求一组数的最大最小值*/*#includevoid main() int i,max,min; int a10; printf(please input ten numbersn); for(i=0;i10;i+) sc
10、anf(%d,&ai); max=a0; min=a0; for(i=1;imax) max=ai; if(aimin) min=ai; printf(max is %d,min is %dn,max,min); */*随机数*/#include#includevoid main() int i,max,min; int a10; for (i=0;i10;i+) ai=rand()%90+10; printf(%dt,ai); max=a0; min=a0; for(i=1;imax) max=ai; if(aimin) min=ai; printf(max=%dtmin=%dn,max,m
11、in);/*8.判断闰年*/#includeint f(int n) if(n%4=0&n%100!=0|n%400=0) return 1; else return 0;void main() int n; printf(please input year:n); scanf(%d,&n); if(f(n) printf(%d是闰年n,n); else printf(%d不是闰年n,n);/*可能会有要输出某一范围内所有闰年,思想一样,用循环调用函数即可*/*9.判断水仙花数(运用循环)#includevoid main() int n,a,b,c,m; printf(please inpu
12、t a number: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(%d is the number we wantn,n); else printf(%d is not the numbern,n);*/*9.输出所有水仙花数(调用函数(书P108为循环做法))*/#includeint f(int n) int a,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) return 1; else return 0;void main() int i,t; for(i=100;i1000;i+
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1