C语言操作题常考编程题库.docx
1、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为标准*/#includevoidmain(){inti,n;doublea,b,c;n=i/400;printf(pleaseinputincome:n);scanf(%d,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:p
3、rintf(需交纳%lf元n,a);break;case3:case4:printf(需交纳%lf元n,b);break;default:printf(需交纳%lf元n,c);break;}}/*2.求一组数的奇数个数,偶数个数和平均值#include#defineN10voidmain(){inta[N];inti,m=0,n=0,sum=0;doubleaverage;printf(pleaseinpu
2、,完数,等等)19、字符串加密;20、统计字符串中字母和数字的个数;/*1.个人所得税计算,以试验指导P24T5为标准*/#includevoidmain(){inti,n;doublea,b,c;n=i/400;printf(pleaseinputincome:n);scanf(%d,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:p
3、rintf(需交纳%lf元n,a);break;case3:case4:printf(需交纳%lf元n,b);break;default:printf(需交纳%lf元n,c);break;}}/*2.求一组数的奇数个数,偶数个数和平均值#include#defineN10voidmain(){inta[N];inti,m=0,n=0,sum=0;doubleaverage;printf(pleaseinpu
t10numbers:n);for(i=0;i#de
4、fineN10voidmain(){inta[N];inti,m=0,n=0,sum=0;doubleaverage;printf(pleaseinput10numbers:n);for(i=0;i0)m++;elsen++;sum+=a[i];}average=(double)sum/N;printf(wehave%dpositivenumbersand%dnagetivenumbersn,m,n);printf(theaverage=%lf,average);}/*3.求二维数组的
5、主次对角线之和*/#include#defineM5#defineN5voidmain(){inta[M][N];inti,j,sum1=0,sum2=0;printf(pleaseinputthematrix:n);for(i=0;i#includeintisPrime(intn){inti;for(i=1;i#includevoidmain(){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;
6、printf(%lf,pi);}//6.两个一维数组相加///*#include#defineN5voidmain(){inta[N],b[N],c[N];inti;printf(pleaseinputthefirstarraya[N]:n);for(i=0;i#defi。省略部分。#include#defineN5voidf(inta[],intn){inti,j;intt;for(i=0;ia[j+1]){t=a[j];a[j]=a[j+1];a[j+1]=t;}}}}*///插入法//#include#d
7、efineN5voidf(inta[],intn){inti,j;intt;for(i=0;i0a[j-1]t){a[j]=a[j-1];--j;}a[j]=t;}}voidmain(){inta[N]={8,2,34,5,12};inti=0;intsize=sizeof(a)/sizeof(int);for(i=0;i#defineN3#defineM3void
4、fineN10voidmain(){inta[N];inti,m=0,n=0,sum=0;doubleaverage;printf(pleaseinput10numbers:n);for(i=0;i0)m++;elsen++;sum+=a[i];}average=(double)sum/N;printf(wehave%dpositivenumbersand%dnagetivenumbersn,m,n);printf(theaverage=%lf,average);}/*3.求二维数组的
5、主次对角线之和*/#include#defineM5#defineN5voidmain(){inta[M][N];inti,j,sum1=0,sum2=0;printf(pleaseinputthematrix:n);for(i=0;i#includeintisPrime(intn){inti;for(i=1;i#includevoidmain(){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;
6、printf(%lf,pi);}//6.两个一维数组相加///*#include#defineN5voidmain(){inta[N],b[N],c[N];inti;printf(pleaseinputthefirstarraya[N]:n);for(i=0;i#defi。省略部分。#include#defineN5voidf(inta[],intn){inti,j;intt;for(i=0;ia[j+1]){t=a[j];a[j]=a[j+1];a[j+1]=t;}}}}*///插入法//#include#d
7、efineN5voidf(inta[],intn){inti,j;intt;for(i=0;i0a[j-1]t){a[j]=a[j-1];--j;}a[j]=t;}}voidmain(){inta[N]={8,2,34,5,12};inti=0;intsize=sizeof(a)/sizeof(int);for(i=0;i#defineN3#defineM3void
main(){inta[M][N],b[M][N];inti,j;printf(pleaseinputa[M][N]n);for(i=0;iin
8、tf(intn){if(n==1||n==0)return1;elsereturnf(n-1)*n;}voidmain(){intn,m;printf(pleaseinputanumber:n);scanf(%d,m=f(n);printf(%d!=%dn,n,m);}/*16.运用递归函数求斐波拉契数列〔前30项〕*/#includeintf(intn){if(n==1||n==2)return1;elsereturnf(n-1)+f(n-2);}voidmain(){inti,k=
9、0;for(i=1;i#include#defineN5voidmain(){intn,i,j,k,a,sum1=0;printf(pleaseinputanumber:n);scanf(%d,for(i=1;i#defineN5intk(inta,intsum){sum=sum*10+a;returnsum;}voidmain(){inta,i=0,j,sum=0;printf(pleaseinputanumber:n);scanf(%d,sum=k(a,k(
10、a,sum));printf(sum=%dn,sum);}//18.求符合条件的整数〔如是某个二位数的平方,个位、十位、百位数各不相同等〕//#includevoidmain(){inta,b,c,n,m;for(m=10;m#include#defineN80voidmain(){charstr[N];char*p;printf(pleaseinputthecode:n);gets(str);p=str;while(*p!=){*p+=2;p++;}printf(%s
11、n,str);}//20.统计字符串中字母和数字的个数//#include#include#include#defineN100c语言用递归函数求n的阶乘
8、tf(intn){if(n==1||n==0)return1;elsereturnf(n-1)*n;}voidmain(){intn,m;printf(pleaseinputanumber:n);scanf(%d,m=f(n);printf(%d!=%dn,n,m);}/*16.运用递归函数求斐波拉契数列〔前30项〕*/#includeintf(intn){if(n==1||n==2)return1;elsereturnf(n-1)+f(n-2);}voidmain(){inti,k=
9、0;for(i=1;i#include#defineN5voidmain(){intn,i,j,k,a,sum1=0;printf(pleaseinputanumber:n);scanf(%d,for(i=1;i#defineN5intk(inta,intsum){sum=sum*10+a;returnsum;}voidmain(){inta,i=0,j,sum=0;printf(pleaseinputanumber:n);scanf(%d,sum=k(a,k(
10、a,sum));printf(sum=%dn,sum);}//18.求符合条件的整数〔如是某个二位数的平方,个位、十位、百位数各不相同等〕//#includevoidmain(){inta,b,c,n,m;for(m=10;m#include#defineN80voidmain(){charstr[N];char*p;printf(pleaseinputthecode:n);gets(str);p=str;while(*p!=){*p+=2;p++;}printf(%s
11、n,str);}//20.统计字符串中字母和数字的个数//#include#include#include#defineN100c语言用递归函数求n的阶乘
voidmain(){charstr[N];inti=0;inta=0,b=0;printf(pleaseinputastring:n);gets(str);while(str[i]!=str[i]!=n){if(isdigit(str[i]))a++;elseif(isalpha(str[i]))b++;i++;}pri
12、ntf(thereare%dlettersand%dnumbersn,b,a);}
12、ntf(thereare%dlettersand%dnumbersn,b,a);}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论