7
8
9
10
第1题:
34 ) 有以下程序
#include <stdio.h>
int f(int n);
main()
{ int a=3,s;
s=f(a);s=s+f(a);printf("%d\n",s);
}
int f(int n)
{ static int a=1;
n+=a++;
return n;
}
程序运行以后的输出结果是
A)7
B)8
C)9
D)10
第2题:
有以下程序:
includedstdio.h>
int f(int n);
main( )
{int a=3,s;
s=f(a);s=s+f(a);printf("%dkn",s);
}
int f(int n)
{static int a=1;
n+=a++;
return n;
}
程序运行后的输出结果是( )。
A.7
B.8
C.9
D.10
本题考查函数的调用。当执行s=f(a)时,进入fun函数,n=n+(a++),n的值为3,a的值为1,a++的意思是先用a的值,再将a加1为2,所以n的结果为4,也就是主函数中f(a)的结果为4;返回主函数,执行s=s+f(a),s为4,再次调用函数,此时n仍为3,a的值刚才已经自加2,所以计算后n的值为5,a自加l为3。返回主函数,f(a)的结果为5,所以s=4+5=9。
第3题:
有以下程序
#include <stdio.h>
void fun(int n,int *p)
{ int f1,f2;
if(n==1||n==2) *p=1;
else
{ fun(n-1,&f1); fun(n-2,&f2);
*p=f1+f2;
}
}
main()
{ int s;
fun(3,&s); printf("%d\n",s);
}
程序的运行结果是
A)2
B)3
C)4
D)5
第4题:
有以下程序 #include <stdio.h> int fun(char s[]) { int n=O; while(*s<='9'&&*s>='0') { n=10*n+*s-'0'; s++; } return (n); } main() { char s[10]={ '6', '1', '*', '4', '*', '9', '*', '0', '*'}; printf("%d\n",fun(s)); }
A.9
B.61490
C.61
D.5
第5题:
以下程序的输出结果是【 】。
include <stdio.h>
define N 5
int fun(int *s,int a,int n)
{ int j;
*s=a j=n;
while(a!=s[j]) j-;
return j;
main()
{ int s[N+1]; int k:
for(k=1 ;k<=N;k++) s[k]=k+1:
print f("%d\n",fun(s,4,N));
}
第6题:
以下程序的输出结果是 #include<stdio.h> in[fun(int n,int *s) {int n,f2; if(n==0‖n==1) *s=1; else {fun(n-1,&f1); fun(n-2,&f2); *s=f1+f2; }} void main() { int x; fun(6,&x); pfintf("\n%d",x);}
A.7
B.13
C.9
D.10
第7题:
有以下程序: #include<string.h> int a=4; int f(int n) {int t=0;static int a=5; if(n%2) {int a=6;t++=a++;} else{int a=7;t+=a++;} return t+a++; } main() {int s=a,i=0; for(;i<2;i++)s+=f(i); printf("%d\n",s); } 程序运行后的输出结果是( )。
A.24
B.28
C.32
D.36
第8题:
( 33 )有以下程序
#include <studio.h>
int f ( int t[],int n ) ;
main
{ int a[4]={1,2,3,4},s;
s=f ( a,4 ) ; printf ( " %d\n " ,s ) ;
}
int f ( int t[],int n )
{ if ( n>0 ) return t[n-1]+f ( t,n-1 ) ;
else return 0 ;
}
程序运行后的输出结果是
A ) 4
B ) 10
C ) 14
D ) 6
第9题:
下面程序的运行结果是[ ]。
include <stdio.h>
int f(int a[],int n)
{ if(n>1)
return a[0]+f(a+1,n-1);
else
return a[0];
}
main()
{int aa[10]={12,3,4,5,6,7,8,9,10},s;
s=f (aa+2,4); printf("%d\n",s); }
第10题:
以下程序的输出结果是 ( )。 #include <iostream> using namespace std; int f(int b[],int m, int n) { int i,s = O; for(i = m;i<n;i+=2) s+=b [i]; return s; } int main ( ) { int x a[] = {1,2,3,4,5,6,7,8,9}; x = f(a,3,7); cout<<x<<end1; return 0; }
A.10
B.18
C.8
D.15