c语言大一期中北航

2024-10-27

c语言大一期中北航(共1篇)

1.c语言大一期中北航 篇一

6.以下程序的输出结果为(D)。main(){ char c;int i;for(i=65;i<68;i++){ c=i+32;switch(c){ case ‘a’:printf(“%c,”,c);break;case ‘b’:case ‘e’:printf(“ok,”);default: printf(“end”);} } } A a,ok,end B a,ok,endend C a,ok,end,end D a,ok,ok 9.以下程序的输出结果为(B)。#define A 3 #define B(a)(A+1)*a main(){ int x;x=3*A+B(7);printf(“x=%dn”,x);} A x=93 B x=37 C x=60 D x=90 三 写出下列程序的运行结果(10分,每小题2分)1.main(){ char c1=‘A’,c2=‘144’,c3=‘x44’,c=0xf5,x=13,a;int i=0122,j=0xa4;printf(“c1=%c,c4=%ctc5=%cn”,c1,c2,c3);printf(“%d,%dn”,i,j);i=-34;j=20;printf(“%d,%d,%dn”,i%j,i&j<<2,sizeof(j));printf(“c=%dn”,c|x);a=c^x<<2;

printf(“a=%dn”,a);} 2.main(){ int x,y=1,z=10;if(y!=0)x=5; printf(“x=%dt”,x);x=1;if(z<0)if(y>0)x=3;else x=5;printf(“x=%dn”,x);if(z=y<0)x=3;else if(y==0)x=5;else x=7;printf(“x=%dt”,x);printf(“z=%dn”,z);} 3.main(){ char s[20]=“I like it.”,t[20]=“Are you?”,c[20];int i=0;while(s[++i]!=‘’)t[i]=s[i];t[i]=0;printf(“string s:%sn”,s);printf(“string t:%sn”,t);} 4.int i=5;main(){ int i=3;{ int i=10;i++;printf(“%dn”,i);

} f1();i+=1;printf(“%dn”,i);} int f1(){ i=i+1;return(i);} 5.main(){ int i=10,a[]={10,20,30,15},*p1;char *b=”Learning”,**p2=&b;p1=&i;printf(“%4d”,*p1+20);for(p1=a;p1a[j]){ t=a[j];a[j]=a[j+1];a[j+1]=t;} printf(“The sorted numbers:n”);for(i=1;i<11;i++)printf(“%4d”,a[i]);printf(“n”);}

2.求100~200间的素数。

Prime(int a)main(){ int m,flag;for(m=101;m<=200;m+=2){ flag=prime(m);if(flag==1)printf(“%4d”,m);} } prime(int a){ int i,k,flag;k=sqrt(a);for(i=2;i<=k;i++)if(a%i==0)break;if(i==k+1)flag=1;else flag=0;}

上一篇:秋天的树叶五年级写秋天的作文400字下一篇:中秋节的故事100字