资源描述:
《国家计算机等级考试二级c常考编程题型》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1.把字符转换成数字并输出chara[]="-12345";inti,m=0;for(i=0;i<=5;i++)printf("a[%d]=%c",i,a[i]);for(i=1;i<=5;i++)m=m*10+a[i]-'0';printf("m=%d",-1*m);注意:a[i]-'0'才能转变成数字!!!!!2.行列变化/*Note:YourchoiceisCIDE*/#include"stdio.h"intfun(inta[][4]){inti,j,temp;for(i=0;i<4;i++){for(j=i+1;j
2、<4;j++){temp=a[i][j];a[i][j]=a[j][i];a[j][i]=temp;}}}voidmain(){inta[4][4]={4,3,2,1,5,6,7,8,9,0,11,12,13,14,23,34,},i,count=0,j;for(i=0;i<4;i++){for(j=0;j<4;j++){printf("a[%d][%d]=%d",i,j,a[i][j]);count++;if(count%4==0)printf("");}}fun(a);for(i=0;i<4;i++){for(j=0;
3、j<4;j++){printf("a[%d][%d]=%d",i,j,a[i][j]);count++;if(count%4==0)printf("");}}}3.将两个数组的数字排序voidmain(){inta[20]={1,4,6,8,21,23,35,56,89,98,678,0},b[20]={2,5,7,9,10,11,15,0},c[40],i=0,j=0,k=0;while(a[i]!=0&&b[j]!=0){if(a[i]>b[j]){c[k]=b[j];j++;}else{c[k]=a[i];i++;}
4、k++;}while(a[i]==0&&b[j]!=0)c[k++]=b[j++];while(b[j]==0&&a[i]!=0)c[k++]=a[i++];c[k]=0;for(k=0;c[k]!=0;k++)printf("%5d",c[k]);}4.将数组中的数字逆序存放/*Note:YourchoiceisCIDE*/#include"stdio.h"voidmain(){inta[10],t,*p,count=0,i;p=a;for(i=0;i<10;i++)scanf("%d",&a[i]);p=a;for(i=0
5、;i<10;i++)printf("%3d",*p++);printf("");for(i=0;i<5;i++){t=a[i];a[i]=a[9-i];a[9-i]=t;}p=a;for(i=0;i<10;i++){printf("%3d",*p++);count++;if(count%5==0)printf("");}}5.将数组中的元素前移n位/*Note:YourchoiceisCIDE*/#include"stdio.h"voidfun(int*str,intp,intn);voidmain(){inta[10
6、]={0,1,2,3,4,5,6,7,8,9},p,i;printf("pleaseinputp:");scanf("%d",&p);fun(a,p,10);for(i=0;i<10;i++)printf("a[%d]=%d",i,a[i]);}voidfun(int*str,intp,intn){intt,i,j;for(i=1;i<=p;i++){t=str[0];for(j=0;j#include
7、#include#includemain(){intn=10;doublex=0.3;inti,t=1;floats,m,s1=0.0;m=x;for(i=2;i<=n;i++){m*=x;t*=i;s1+=(m/t);}printf("s1=%d",s1);printf("s=%d",s1+x+1);}7.偶数分解成素数之和相加#include"stdio.h"#include"math.h"intadd(int);intmain(){inti,j,d;for(i=6;
8、i<=50;i+=2){for(j=2;j<=i;j++){d=i-j;if(d>=2){add(j);add(d);if(add(j)&&add(d)==1)printf("%d=%d+%d",i,j,d);}}}}intadd(inti){intj;for(j=2;j