case 1:printf(“*”);break; default: printf(“*”);break;} case 2:printf(“*”);}}
10.以下程序的输出结果是 a=22 。 int fun() {static int i=2; int s=1; s+=i;i++; return s;} main() {int i,a=10; for(i=2;i<5;i++) a+=fun();
printf(\
11.以下程序段的输出结果是 97531 。 int a[10]={9,8,7,6,5,4,3,2,1,0},*p; for(p=a;p<=a+9;p+=2) printf(“%d”,*p);
12.以下程序的输出结果是 6 15 15 。 int t=1; int fun(int p) {static int t=5; t+=p;
printf(\return (t);} main() {int a=3;
printf(\
13.以下程序的输出结果是 -5,-12,-7 。 void sub(int x,int y,int *z) { *z=y-x; }
main() { int a,b,c;
sub(10,5,&a); sub(7,a,&b); sub(a,b,&c); printf(“%d,%d,%d\\n”,a,b,c);}
14.以下程序段的输出结果是 15 。 main()
{int a[]={1,2,3,4,5,6,7,8,9,10},b=9,i; for(i=0;i<3;i++) b+=a[i]; printf(\
15.以下程序段的输出结果是 16 。 int fun(int n) {if (n==1) return 1; else return n+fun(n-2);} main()
{printf(\五、编程题
1.编程求:S=1/1-1/3+1/5-1/7+…+1/99的值。 #include
printf(\}
2.若给定数组a[12]={15,6,22,34,1,64,52,7,12,32,24,45},请编程对它们进行降序排序并输出。 #include
int a[12]={15,6,22,34,1,64,52,7,12,32,24,45},i,j,l,temp; for(i=0;i<12;i++) for(j=0;j<12;j++) if(a[i]>a[j]) {temp=a[i]; a[i]=a[j]; a[j]=temp;} for(l=0;l<12;l++) printf(\}
3.编写程序,求e的值。e≈1+1/1!+1/2!+1/3!+1/4!+…+1/n!。 #include
printf(\
}
4.输入一个字符串s1,把s1中所有的非数字字符复制到s2中并输出。 例如:s1[]=“abcd1234%6#$ ABC246”,则s2[]= “abcd%#$ ABC”。 #include
int i=0,j=0;
char ch,s1[1024],s2[1024]; gets(s1);
while((ch=s1[i++])!='\\0') {
if(ch<'0'||ch>'9') s2[j++]=ch; }
s2[j]='\\0'; puts(s2); }
5.编写程序,求e的值。e≈1+1/1!+1/2!+1/3!+1/4!+…+1/n!。 #include
}
printf(\}
6.输入一个字符串s1,把s1中所有的非数字字符复制到s2中并输出。 例如:s1[]=“abcd1234%6#$ ABC246”,则s2[]= “abcd%#$ ABC”。 #include
int i=0,j=0;
char ch,s1[1024],s2[1024]; gets(s1);
while((ch=s1[i++])!='\\0') {
if(ch<'0'||ch>'9') s2[j++]=ch; }
s2[j]='\\0'; puts(s2); }