南昌大学C语言考试题库(共34页).doc
精选优质文档-倾情为你奉上一、阅读程序写出程序运行结果阅读以下程序并写出其运行结果#include <stdio.h>#include <stdlib.h>int fun(char s,int c) char *q=s; for(; *q; q+) if(*q != c) *(s+)=*q; *s=0; main() static char str="turbo c and borland c+" char ch; fun(str,'c'); printf("str=%sn",str); system("pause");程序的运行结果是str=turbo and Borland +阅读以下程序并写出其运行结果#include <stdio.h>#include <stdlib.h>void fun(int a, int b, long *c) *c=a/10*10+a%10*1000+b/10*100+b%10; main() int a=42,b=25; long c; fun(a, b, &c); printf("The result is: %ldn", c); system("pause");程序的运行结果是 the result is: 2245 请按任意键继续阅读以下程序并写出其运行结果#include <stdio.h>void fun(int *s, int nl, int n2) int i, j, t ; i=nl; j=n2; while(i<j) t=si; si=sj; sj=t; i+; j-; main() int a10=1,2,3,4,5,6,7,8,9,0,k;fun(a,0,3); fun(a,4,9); fun(a,0,9); for(k=0;k<10;k+)printf(“%d”,ak); printf(“n”); 程序运行的结果是 Press any key to continue阅读以下程序并写出其运行结果#include<stdio.h> main() int i=1; while(!(i%2=1)&&(i%3=2)&&(i%5=4)&&(i%6=5)&&(i%7=0) +i; printf("n >> The ladder has %d stages.n",i); 程序的运行结果是阅读以下程序并写出其运行结果#include <stdio.h>#define ROW 3#define COL 4main()int matrixAROWCOL=11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22; int matrixBCOLROW;int i,j;printf("%d*%d:n",ROW,COL);for( i=0; i<ROW; i+ ) for( j=0; j<COL; j+ )matrixBji = matrixAij;printf("MatrixB,");printf("%d*%d:n",COL,ROW);for( i=0; i<COL; i+ )for( j=0; j<ROW; j+ )printf("%8d",matrixBij);printf("n");system("pause");程序的运行结果是3*4 Matrix B 4*311 15 1912 16 2013 17 2114 18 22阅读以下程序并写出其运行结果#include <stdio.h>#define N 10main()int primesN;int pc,m,k;printf("n The first %d prime numbers are:n",N);primes0=2;pc =1;m =3;while(pc<N)k=0;while(primesk*primesk<=m)if(m%primesk=0) m+=2; k=1;elsek+;primespc+=m;m+=2;for(k=0;k<pc;k+)printf("%4d",primesk);system("pause");程序的运行结果是the fiest 10 prime numbers are2 3 5 7 11 13 17 19 23 29阅读以下程序并写出其运行结果#include <stdio.h>#include <string.h>void fun(char *s ,int n) char *t; int i,j; for(i=0;i<n-1;i+) for(j=i+1;j<n;j+)if(strlen(si)>strlen(sj) t=si;si=sj;sj=t;main() char *ss=“bcc”,”bbcc”,”xy”,”aaaacc”,”aabcc” ;fun(ss,5); printf(“%s,%sn”,ss0,ss4);程序的运行结果是阅读以下程序并写出其运行结果#include <stdio.h>void fun(char *a, char *b) while(*a=*) a+; while(*b=*a) b+;a+;main() char *s=”*a*b*”,t80;fun(s,t); puts(t); 程序的运行结果是阅读以下程序并写出其运行结果#include <stdio.h>main() FILE *fp; int a10=1,2,3,i,n;fp=fopen(“dl.dat”,”w”);for(i=0;i<3;i+) fprintf(fp,”%d”,ai);fprintf(fp,”n”);fclose(fp);fp=fopen(“dl.dat”,”r”);fscanf(fp,”%d”,&n);fclose(fp);printf(“%dn”,n);程序的运行结果是阅读以下程序并写出其运行结果#include<stdio.h> void swap( int *a, int *b ) int *t ; t=a; a=b; b=t; main() int i=3,j=5,*p=&i,*q=&j; swap(p,q); printf(“%d %dn”,*p,*q); 程序的运行结果是阅读以下程序并写出其运行结果int circle(int n, int d)int s=0,m=n;while(m)s=s*d+m%d;m/=d;return s=n;int num=232,27,851;int scale=2,10,16;main()int i,j;for(i=0;i<sizeof(num)/sizeof(num0);i+)for(j=0;j<sizeof(scale)/sizeof(scale0);j+)if(circle(numi,scalej)printf("%d -> (%d) is a Circle Number!n",numi,scalej);elseprintf("%d -> (%d) is not a Circle Number!n",numi,scalej);程序的运行结果是 答案太长不想写阅读以下程序并写出其运行结果#include <stdio.h>#define NULL 0int *search2(int *pa,int *pb,int an,int bn)int *ca,*cb;ca=pa;cb=pb;while(ca<pa+an&&cb<pb+bn)if(*ca<*cb) ca+;else if(*ca>*cb) cb+;elsereturn ca;/*返回在这两个数表中找到相等元素*/return NULL;main( )int *vp,i;int a =1,3,5,7,9,13,15,27,29,37;int b =2,4,6,8,10,13,14,27,29,37;puts("The elements of array a is:");for(i=0;i<sizeof(a)/sizeof(a0);i+)printf(" %d",ai);puts("nThe elements of array b is:");for(i=0;i<sizeof(b)/sizeof(b0);i+)printf(" %d",bi);vp=search2(a,b,sizeof a/sizeof a0,sizeof b/sizeof b0);if(vp) printf("nThe first same number in both arrays is %dn",*vp);else printf("Not found!n");程序的运行结果是阅读以下程序并写出其运行结果#include <stdio.h>main()int i, j;char ch;i=1;while(i<=5)j=1;ch='a'while(j<=i)printf("%2c", ch);ch=ch+1;j+;printf("n");i+; 程序的运行结果是阅读以下程序并写出其运行结果#include <stdio.h>rest(int a, int n)int i,low,high,t;for(i=0,low=0,high=n-1;i<=high;)if(ai>0)t=ai;ai=ahigh;ahigh=t;high-;else if(ai=0)i+;elset=ai;ai=alow;alow=t;low+;i+;int s=8,4,0,-1,6,0,-5;main()int i;printf("n The arry before rest is:n");for(i=0;i<sizeof(s)/sizeof(s0);i+)printf("%4d",si);rest(s,sizeof(s)/sizeof(s0);printf("n The arry after rest is:n");for(i=0;i<sizeof(s)/sizeof(s0);i+)printf("%4d",si);程序的运行结果是the arry before rest is 8 4 0 -1 6 0 -5 the arry after rest is -5 -1 0 0 6 4 8阅读以下程序并写出其运行结果#include <stdio.h>#include <string.h>typedef struct char name9; char sex; float score2; STU;void f( STU a) STU b=“Zhao” ,m,85.0,90.0 ; int i;strcpy(a.name,b.name);a.sex=b.sex;for(i=0;i<2;i+) a.scorei=b.scorei;main() STU c=“Qian”,p,95.0,92.0;f(c); printf(“%s,%c,%2.0f,%2.0fn”,c.name,c.sex,c.score0,c.score1); 程序的运行结果是阅读以下程序并写出其运行结果 #include<stdio.h> main() int x,y,z,j=0; printf("n The possible plans to buy 100 fowls with 100 Yuan are:nn"); for(x=0;x<=20;x+) for(y=0;y<=33;y+) z=100-x-y; if(z%3=0&&5*x+3*y+z/3=100) printf("%2d: cock=%2d hen=%2d chicken=%2dn",+j,x,y,z); 程序的运行结果是阅读以下程序并写出其运行结果#include<stdio.h> void fun(int x) if(x/2>0) fun(x/2); printf(“%d ”,x); main() fun(3); printf(“n”); 程序的运行结果是阅读以下程序并写出其运行结果#define MAX(a,b) (a>b)?a:bmain()int x, y;x=25;y=56;printf("the result is: %dn", MAX(x,y);程序的运行结果是the result is 56阅读以下程序并写出其运行结果 #include <stdio.h>#define ROWS 4#define COLS 4int numsROWSCOLS=1000,1000,1000,1000, 900,500,400,100, 90,50,40,10, 9,5,4,1;char *romsROWSCOLS="m","m","m","m", "cm","d","cd","c", "xc","l","xl","x", "ix","v","iv","i"main(int argc,char *argv )int low=1000,high=1012;char roman25;for(;low<=high;low+)to_roman(low,roman);printf("%dt%sn",low,roman);system("pause");to_roman(int decimal,char roman )int power,index;roman0='0'for(power=0;power<ROWS;power+)for(index=0;index<COLS;index+)while(decimal>=numspowerindex)strcat(roman,romspowerindex);decimal-=numspowerindex;程序的运行结果是1000 m 1001 mi 1002 mii 1003 miii 1004 miv 1005 mv 1006 mvi 1007 mvii 1008 mviii 1009 mix 1010 mx 1011 mxi 1012 mxii#include<stdio.h> int Fun(int x) static int y = 0;y += x;return y; main() int x = 10, y = 0, k;for(k=0; k<2; k+) y = Fun(x);printf("y = %dn", y); 运行结果是:#include<stdio.h>main ( )char a = "programming" , b = "language" ;char *p1, *p2 ;int i;p1 = a; p2 = b;for (i=0; i<7; i+)if (*(p1+i) = *(p2+i) printf("%c" ,*(p1+i) ;printf("n");运行结果是: #include <stdio.h>main()int a=10; int a=15; printf(“a.1=%d,”,a); printf(“a.2=%dn”,a);运行结果是:#include <stdio.h>main()int i=0; while(1) printf(“*”); i+; if(i<3) break;printf(“n”);运行结果是:int runc(int a,int b)return(a+b);main()int x=2,y=5,z=8,r;r=runc(runc(x,y),z);printf(“%dn”,r);执行结果是: 15阅读以下程序并写出其运行结果#incude <stdio.h>main()int i, n3, n2, n1;i=1;while(i<=99)n3=i/100;n2=(i-n3*100)/10;n1=i%10;if(i%3=0)&&(n2=5|n1=5)printf("%5d", i);i+;程序的运行结果是 15 45 51 54 57 75阅读以下程序并写出其运行结果 main ( ) int a66,i,j ; for (i=1; i<6 ; i+) for (j=1 ; j<6 ; j+) aij=(i/j)*(j/i) ; for (i=1;i<6 ; i+) for (j=1 ; j<6 ; j+) printf(“%2d”,aij) ; printf(“n”); 程序的运行结果是 1000001000001000001000001阅读以下程序并写出其运行结果#include <stdio.h>#include <stdlib.h>struct ks int a; int *b ; s4, *p ;main ( ) int n=1, i ; for (i=0 ; i<4; i+) si.a = n ; si.b=&si.a ; n=n+2 ; p=&s0 ; p+ ; printf(“%d, %dn”,(+p)->a,(p+)->a) ;程序的运行结果是阅读以下程序并写出其运行结果#include <stdio.h>void fun(int *s, int nl, int n2) int i, j, t ; i=nl; j=n2; while(i<j) t=si; si=sj; sj=t; i+; j-; main() int a10=1,2,3,4,5,6,7,8,9,0,k;fun(a,0,3); fun(a,4,9); fun(a,0,9); for(k=0;k<10;k+)printf(“%d”,ak); printf(“n”); 程序运行的结果是阅读以下程序并写出其结果func (int a,int b) static int m=0,i=2; i+=m+1; m=i+a+b; return (m);main ( ) int k=4,m=1,p1,p2; p1=func(k,m) ; p2=func(k,m) ; printf(“%d,%dn”,p1,p2) ;程序的运行结果是 8 17阅读以下程序并写出其运行结果struct man char name20 ; int age ; person = “liming”, 18, “wanghua”, 19,”zhangping”,20 ;main ( ) int old = 0 ; struct man *p=person, *q ; for ( ; p<=&person2; p+) if (old<p->age) q=p ; old=p->age ; printf(“$s %dn”,q->name,q->age) ;程序的运行结果是 zhongping 20阅读以下程序并写出其运行结果 #include<stdio.h> main() int x,y,z,j=0; printf("n The possible plans to buy 100 fowls with 100 Yuan are:nn"); for(x=0;x<=20;x+) for(y=0;y<=33;y+) z=100-x-y; if(z%3=0&&5*x+3*y+z/3=100) printf("%2d: cock=%2d hen=%2d chicken=%2dn",+j,x,y,z); 程序的运行结果是阅读以下程序并写出其运行结果#include<stdio.h> void fun(int x) if(x/2>0) fun(x/2); printf(“%d ”,x); main() fun(3); printf(“n”); 程序的运行结果是阅读以下程序并写出其运行结果#define MAX(a,b) (a>b)?a:bmain()int x, y;x=25;y=56;printf("the result is: %dn", MAX(x,y);程序的运行结果是 没找上答案阅读以下程序并写出其运行结果 #include <stdio.h>#define ROWS 4#define COLS 4int numsROWSCOLS=1000,1000,1000,1000, 900,500,400,100, 90,50,40,10, 9,5,4,1;char *romsROWSCOLS="m","m","m","m", "cm","d","cd","c", "xc","l","xl","x", "ix","v","iv","i"main(int argc,char *argv )int low=1000,high=1012;char roman25;for(;low<=high;low+)to_roman(low,roman);printf("%dt%sn",low,roman);system("pause");to_roman(int decimal,char roman )int power,index;roman0='0'for(power=0;power<ROWS;power+)for(index=0;index<COLS;index+)while(decimal>=numspowerindex)strcat(roman,romspowerindex);decimal-=numspowerindex;程序的运行结果是 没找上答案阅读以下程序并写出其运行结果#incude <stdio.h>main()int i, n3, n2, n1;i=1;while(i<=99)n3=i/100;n2=(i-n3*100)/10;n1=i%10;if(i%3=0)&&(n2=5|n1=5)printf("%5d", i);i+;程序的运行结果是 没找上答案二填空题,在下列代码段中的空白处填入正确的语句 以下程序求3个整数的最小公倍数,请填空#inlcude <stdio.h>int fun(int, tint , int );main() int x1, x2, x3, i=1, j, x0; printf("input 3 integers:"); scanf("%d%d%d", &x1, &x2, &x3); x0=fun(x1, x2, x3); while(1) j=x0*i; if_j%x1=0&&_j%x2=0&&j%x3=0 _break; i+; printf("Result is %dn",j);int fun(int x, int y, int z) if(x>y && x>z) return x; else if_y>x &&y>z_ return y; else return z;以下程序的功能是计算函数,请填空使程序完整。# include <stdio.h> ;main ( ) float x,y,z,f ; scanf(“%f,%f,%f”,&x,&y,&z); f = fun ( ); f += fun ( ); printf(“f=%d”,f);float fun(float a,float b) return (a/b) ;下述程序用“碾转相除法”计算两个整数m和n的最大公约数。该方法的基本思想是计算m和n相除的余数,如果余数为0则结束,此时的被除数就是最大公约数。否则,将除数作为新的被除数,余数作为新的除数,继续计算m和n相除的余数,判断是否为0,等等,请填空使程序完整。 main ( ) int m,n,w; scanf(“%d,%d”,&m,&n); while (n) w = m%n ; m = n ; n = m ; printf(“%d”,m);以下函数求s=请填空float fun(int n)int i;double s1=0, s2=_,s3=_, s=0;for(i=1; i<=n; i+)s3=s3*i;s1=_;for(i=1; i<=n; i+)s2=s2+_;_;return s; 下面以下程序输出a, b, c三个变量中的最小值,请填空。 #include <stdio.h>main() int a, b, c, t1, t2; scanf("%d%d%d", &a, &b, &c); t1=a<b?_a:b_; t2=c<t1?_c:t1_; printf("%dn", t2);已知如下公式: 下面程序的功能使根据上述公式输出满足精度要求的eps的值,请填空使程序完整。main ( ) double s = 0.0, eps, t=1.0; int n ; scanf (“%lf”,&eps); for (n=1 ; ; n+) s+=t ; t= ; ;计算1+1/2+1/4+1/50的值,并显示出来。 main() int i=2; float sum=1.0; while(i<= 50 ) sum+=1/ double i ; i+=2; printf(“sum=%fn”,sum);