您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 2015年西工大C语言上机考试题库-全
1.1:2:32.一堆83.8的次数4.A*B5.N边形面积6.参加竞赛7.草坪喷水8.插入排序9.查找10.车牌号11.成绩转化12.大数(见NOJ)13.大写变小写14.到底星期几15.等比数列16.找到正整数符合要求17、韩信点兵18.回文字符串鸡的体重计算数据整数部分加密阶乘恐怖水母卡片快速排序两人三足逆序输出偶数和三角形面积士兵移动输出位数数列数字加密数组元素和水仙花数提取字符串添加行号舞伴配对相乘后位数相加销售记录星期几星座幸运数学号循环移位月份天数月份转换英语运费字符串替换字符输出总分最高最大公约数最大值最小值最小公倍数左下角1.1:2:3#includestdio.h#includemath.hintmain(){inti=0,j=0,k=0,a=0,b=0,c=0,l=0,m=0,n=0,d=0,p=0,q=0;for(i=1;i=3;i++){for(j=1;j=9;j++){if(i!=j){for(k=1;k=9;k++){if(k!=j&&i!=k){a=i*100+j*10+k;b=a*2;c=a*3;l=b%10,d=c%10;m=(b%100)/10,p=(c%100)/10;n=b/100,q=c/100;if(l!=0&&m!=0&&n!=0&&d!=0&&p!=0&&q!=0)if(i!=l&&i!=m&&i!=n&&j!=l&&j!=m&&j!=n&&k!=l&&k!=m&&k!=n)if(i!=d&&i!=p&&i!=q&&j!=d&&j!=p&&j!=q&&k!=d&&k!=p&&k!=q)if(l!=d&&l!=p&&l!=q&&m!=d&&m!=p&&m!=q&&n!=d&&n!=p&&n!=q)printf(%d%d%d\n,a,b,c);}}}}}return0;}2.一堆8#includestdio.hintmain(){inta,b[10],m=0,n=0,p;inti,j,k;scanf(%d,&a);for(i=1;i=a;i++){m=0;n=0;p=i;for(j=0;p!=0;j++){b[j]=p%10;p=p/10;}for(k=0;kj;k++){m=m+b[k];if(b[k]==8){n=1;}}if(m%8==0){printf(%d,i);continue;}if(i%8==0){printf(%d,i);continue;}if(n==1){printf(%d,i);continue;}}return0;}3.8的次数4.A*B#includestdio.h#includestring.h#includestdlib.hvoidcheng(chara[],charb[]){inti,j,ca,cb,*s;ca=strlen(a);cb=strlen(b);s=(int*)malloc(sizeof(int)*(ca+cb));for(i=0;ica+cb;i++)s[i]=0;for(i=0;ica;i++)for(j=0;jcb;j++)s[i+j+1]+=(a[i]-'0')*(b[j]-'0');for(i=ca+cb-1;i=0;i--)if(s[i]=10){s[i-1]+=s[i]/10;s[i]%=10;}i=0;while(s[i]==0)i++;for(;ica+cb;i++)printf(%d,s[i]);printf(\n);free(s);}intmain(){chara[100],b[100];gets(a),gets(b);if(a[0]=='-'&&b[0]!='-'){printf(-);cheng(&a[1],b);}elseif(a[0]=='-'&&b[0]=='-'){cheng(&a[1],&b[1]);}elseif(a[0]!='-'&&b[0]=='-'){printf(-);cheng(a,&b[1]);}elsecheng(a,b);return0;}5.N边形面积#includestdio.h#includemath.h#definePI3.1415926intmain(){doubles,a;intn;scanf(%d%lf,&n,&a);s=a*a*n/(2*2*tan(PI/n));printf(%.2lf\n,s);return0;}6.参加竞赛#includestdio.hintmain(){inta,b,c,d,e;for(a=0;a2;a++)for(b=0;b2;b++)for(c=0;c2;c++)for(d=0;d2;d++)for(e=0;e2;e++)if(((a==1&&b==1)||(a==0&&b==0))&&((b==0&&c==1)||(b==1&&c==0))&&((c==1&&d==1)||(c==0&&d==0))&&(!(d==0&&e==0))&&((e==1&&a==1&&d==1)||(e==0))){if(a==1){printf(A);}if(b==1){printf(B);}if(c==1){printf(C);}if(d==1){printf(D);}if(e==1){printf(E);}}return0;}7.草坪喷水8.插入排序#includestdio.hvoidsort(inta[],intn){inti;intk;intt;for(i=1;in;i++){t=a[i];k=i-1;while(ta[k]){a[k+1]=a[k];k--;if(k==-1)break;}a[k+1]=t;}}intmain(){intn;inta[100];inti;scanf(%d,&n);for(i=0;in;i++)scanf(%d,&a[i]);sort(a,n);printf(\n);for(i=0;in;i++)if(i==n-1)printf(%d\n,a[i]);elseprintf(%d,a[i]);return0;}9.查找10.车牌号#includestdio.h#includemath.hintmain(){inti,j,n;for(i=1;i=9;i++){for(j=0;j=9;j++){for(n=33;n=100;n++){if((n*n)==(i*1100+j*11))printf(%d,i*1100+j*11);}}}return0;}11.成绩转化乘完倒序尺子刻度大数除法12.大数减法#includestdio.h#includestring.h#definemax(a,b)ab?a:b#definemin(a,b)ab?b:aintsum[101];voidjia(chara[],charb[]){intflag=0,i,len1,len2,lenmax,lenmin;len1=strlen(a),len2=strlen(b);lenmax=max(len1,len2),lenmin=min(len1,len2);for(i=1;i=lenmax;i++){if(i=lenmin){sum[lenmax-i]=a[len1-i]+b[len2-i]-'0'-'0'+flag;if(sum[lenmax-i]=10){sum[lenmax-i]=sum[lenmax-i]-10;flag=1;}elseflag=0;}else{if(len1len2){sum[lenmax-i]=a[len1-i]-'0'+flag;if(sum[lenmax-i]=10){sum[lenmax-i]=sum[lenmax-i]-10;flag=1;}elseflag=0;}else{sum[lenmax-i]=b[len2-i]-'0'+flag;if(sum[lenmax-i]=10){sum[lenmax-i]=sum[lenmax-i]-10;flag=1;}elseflag=0;}}}if(flag==1)printf(1);for(i=0;ilenmax;i++)printf(%d,sum[i]);printf(\n);}voidjian(chara[],charb[]){intflag=0,i;intlen1,len2;len1=strlen(a),len2=strlen(b);for(i=1;i=len1;i++){if(i=len2){if(a[len1-i]-b[len2-i]-flag=0){sum[len1-i]=a[len1-i]-b[len2-i]-flag;flag=0;}else{sum[len1-i]=a[len1-i]-b[len2-i]-flag+10;flag=1;}}else{if(a[len1-i]-flag-'0'=0){sum[len1-i]=a[len1-i]-flag-'0';flag=0;}else{sum[len1-i]=a[len1-i]-flag+10-'0';flag=1;}}}for(i=0;ilen1&&sum[i]==0;i++);for(;ilen1;i++)printf(%d,sum[i]);printf(\n);}voidcompare(chara[],charb[]){intlen1,len2;len1=strlen(a),len2=strlen(b);if(len1len2||(len1==len2&&strcmp(a,b)0))jian(a,b);elseif(strcmp(a,b)!=0){printf(-);jian(b,a);}elseprintf(0\n);}intmain(){chara[100],b[100];gets(a);gets(b);if(a[0]=='-'&&b[0]!='-'){printf(-);jia(&a[1],b);}elseif(a[0]=='-'&&b[0]=='-')compare(&b[1],&a[1]);elseif(a[0]!='-'&&b[0]=='-')jia(a,&b[1]);elsecompare(a,b);return0;}13.大写变小写#includestdio.h#includestring.hintmain(){chars[80];intlen,i;gets(s);len=strlen(s);for(i=0;ilen;i++){if(s[i]='a'&&s[i]='z')s[i]=s[i]-32;}puts(s);return0;}14.到底星期几15.等比数列#includestdio.h#includestdlib.hintmain(){intm,n,sum;scanf(%d,&m);for(n=1;;n++){sum=(3*n-1)*n/2;if(summ)break;}printf(%d,n);return0;}16.找到正整数符合要求#includestdio.hintmain(){intk,x=1,y=1;floata,b;scanf(%d,&k);for(;y=5000;y++){for(x=y;x=5000;x++){a=1.0/k;b=1.0/x+1.0/y;if(a==b)printf(1/%d=1/%d+1/%d\n,k,x,y);}}return0;}17、韩信点兵#includestdio.hintmain(){intn,i;for(i=0;;i++){if(i%5==2&&i%6==3&&i%7==4&&i%11==5){printf(%d,i);break;}}return0;}18.回文字符串#includestdio.h#includestring.h#includectype.h#defineMAXN5000+10charbuf[MAXN],s[MA
本文标题:2015年西工大C语言上机考试题库-全
链接地址:https://www.777doc.com/doc-4006486 .html