您好,欢迎访问三七文档
1.abc为一位整数求满足abc加cba等于1333的各值#includestdio.hvoidmain(){inta,b,c;for(a=0;a=9;a++)for(b=0;b=9;b++)for(c=0;c=9;c++)if(100*(a+c)+20*b+a+c==1333)printf(a=%db=%dc=%d\n,a,b,c);}2,a加a的平方加到a的n次方#includestdio.hvoidmain(){inta,n,i;longk=1,s=0;scanf(%d%d,&a,&n);for(i=1;i=n;i++){k=k*a;s=s+k;}printf(a=%dn=%d\ns=%ld\n,a,n,s);}3,插入数据到数组#includestdio.hvoidmain(){inta[11]={1,4,6,9,13,16,19,28,40,100};inttemp1,temp2,num,end,i,j;printf(初始数组如下:);for(i=0;i10;i++)printf(%5d,a[i]);printf(\n);printf(输入插入数据:);scanf(%d,&num);end=a[9];if(numend)a[10]=num;else{for(i=0;i10;i++)if(a[i]num){for(j=9;j=i;j--)a[j+1]=a[j];a[i]=num;break;}}for(i=0;j11;i++)printf(%5d,a[i]);printf(\n);}4,从键盘输入一个字符串,再输入两个正整数m和n,输出字符串中从m开始,连续n个字符。例如:输入abcdefg,2,3,输出bcd#includestdio.hvoidmain(){chara[100];gets(a);intm,n,i;scanf(%d%d,&m,&n);for(i=m-1;im+n-1;i++)printf(%c,a[i]);printf(\n);}5,大小写字母的转换#includestdio.hvoidmain(){charc1,c2;c1='a';c2='b';c1=c1-32;c2=c2-32;printf(%c%c,c1,c2);}6,递归法求n!#includestdio.hvoidmain(){floatfac(intn);intn;floaty;printf(inputanintegernumber:);scanf(%d,&n);y=fac(n);printf(%d!=%10.0f\n,n,y);}floatfac(intn){floatf;if(n0){printf(n0,dataerror!);}elseif(n==0||n==1)f=1;elsef=fac(n-1)*n;return(f);}7,对角线元素之和#includestdio.hvoidmain(){inta[3][3],sum=0;inti,j;printf(请输入矩阵元素:\n);for(i=0;i3;i++)for(j=0;j3;j++)scanf(%f,a[i][j]);for(i=0;i3;i++)sum=sum+a[i][i];printf(对角元素之和=6.2f,sum);}8,给一个不多于5位的正整数,要求1求它是几位数2分别打印出每一位数字#includestdio.hvoidmain(){longintnum;intplace;printf(请输入一个整数(0~99999):);scanf(%ld,&num);if(num9999)place=5;elseif(num999)place=4;elseif(num99)place=3;elseif(num9)place=2;elseplace=1;printf(place=%d\n,place);printf(每位数字为:);}9,猴子摘桃#includestdio.hvoidmain(){intday,x1,x2;day=9;x2=1;while(day0){x1=(x2+1)*2;x2=x1;day--;}printf(total=%d\n,x1);}10,计算并输出1—200之间不能被5整除的整数之和#includestdio.hvoidmain(){inti,sum=0;for(i=1;i=200;i++)if(i%5!=0)sum=sum+i;printf(%d\n,sum);}11,将输入的一个字符串中的a用xinghao代替输出#includestdio.hvoidmain(){charstr[10];inti;scanf(%s,str);for(i=0;i10;i++)if(str[i]=='a')str[i]='*';puts(str);}12,将一个大写字母改用小写输出#includestdio.hvoidmain(){charc1,c2;c1=getchar();printf(%c,%d\n,c1,c1);c2=c1+32;printf(%c,%d\n,c2,c2);}13,将一个数组逆序存放#includestdio.h#defineN5voidmain(){inta[N]={8,6,5,4,1},i,temp;printf(enterarray:\n);for(i=0;iN;i++)scanf(%d,&a[i]);printf(arraya:\n);for(i=0;iN;i++)printf(%4d,a[i]);for(i=0;iN/2;i++){temp=a[i];a[i]=a[N-i-1];a[N-i-1]=temp;}printf(\nNow,arraya:\n);for(i=0;iN;i++)printf(%4d,a[i]);printf(\n);}14,矩阵的行列互换#includestdio.h#defineN3intarray[N][N];voidmain(){voidconvert(intarray[][3]);inti,j;printf(intputarray:\n);for(i=0;iN;i++)for(j=i+1;jN;j++)scanf(%d,array[i][j]);printf(\noriginalarray:\n);for(i=0;iN;i++){for(j=0;jN;j++)printf(%5d,array[i][j]);printf(\n);}}voidconvert(intarray[][3]){inti,j,t;for(i=0;iN;i++)for(j=i+1;jN;j++){t=array[i][j];array[i][j]=array[j][i];array[j][i]=t;}}15,连接两个字符串#includestdio.hvoidmain(){chars1[80],s2[40];inti=0,j=0;printf(\n请输入字符串1:);scanf(%s,s1);printf(\n请输入字符串2:);scanf(%s,s2);while(s1[i]!='\0')i++;while(s2[j]!='\0')s1[i++]=s2[j++];s1[i]='\0';printf(\n连接后字符串为:%s,s1);}16,判断m是否为素数#includestdio.h#includemath.hvoidmain(){intm,i,k;scanf(%d,&m);k=sqrt(m);for(i=2;i=k;i++)if(m%i==0)break;if(ik)printf(%disaprimenumber\n,m);elseprintf(%disnotaprimenumber\n,m);}17,判断整数是否为素数#includestdio.hvoidmain(){intprime(int);intn;printf(\nintputaninteger:);scanf(%d,&n);if(prime(n))printf(\n%disaprime.\n,n);elseprintf(\n%disnotaprime.\n,n);}intprime(intn){intflag=1,i;for(i=2;in/2&&flag==1;i++)if(n%i==0)flag=0;return(flag);}18,起泡法排序#includestdio.h#includestring.h#defineN10charstr[N];voidmain(){voidsort(char[]);inti,flag;for(flag=1;flag==1;){printf(intputstring:\n);scanf(%s,&str);if(strlen(str)N)printf(stringtoolong,intputagain!);elseflag=0;}sort(str);printf(stringsorted:);for(i=0;iN;i++)printf(%c,str[i]);printf(\n);}voidsort(charstr[]){inti,j;chart;for(j=1;jN;j++)for(i=0;(iN-j)&&(str[i]!='\0');i++)if(str[i]str[i+1]){t=str[i];str[i]=str[i+1];str[i+1]=t;}}19,求1!+2!+++20!#includestdio.hvoidmain(){floats=0,t=1;intn;for(n=1;n=20;n++){t=t*n;s=s+t;}printf(1!+2!+3!+...+20!=%e\n,s);}20,求1到100的和#includestdio.hvoidmain(){inti,sum=0;i=1;while(i=100){sum=sum+i;i++;}printf(%d\n,sum);}21,求1到100的和加上1到50的平方和再加上1到10的倒数和#includestdio.hvoidmain(){intn1=100,n2=50,n3=10;floatk;floats1=0,s2=0,s3=0;for(k=1;k=n1;k++)s1=s1+k;for(k=1;k=n2;k++)s2=s2+k*k;for(k=1;k=n3;k++)s3=s3+1/k;printf(sum=%8.2f\n,s1+s2+s3);}22,求5!#includestdio.hvoidmain(){intt=1,i=2;do{t=t*i;i++;}while(i=5);printf(t=%d\n,t);}23,求100~200间的全部素数#includestdio.h#includemath.hvoidmain(){intm,k,i,n=0;for(m=101;m=200;m=m+2){k=sqrt(m);for(i=2;i=k;i++)if(m%i==0)break;if(i=k+1){printf(%d,m);n=n+1;}if(n%10==0)printf(\n);}printf(\n);}24,求100之内能被17整除的最大的数#includestdio.hvoidmain(){inti;for(i=100;i=1;i--)if(i%17==0){printf(%d\n,i);break;}}25,求Fibonacci数列的前40个数一、#includestdio.hvoidmain(){longintf1,f2;inti;f1=1;f2=1;for(i=1;i=20;i++){printf(%12ld%12ld,f1,f2);if(i%2==0)printf(\n);f1=f1+f2;f2=f2+f1;}}二、
本文标题:C程序设计编程题
链接地址:https://www.777doc.com/doc-3969294 .html