C语言函数习题及答案(20200506225202)

5.

#include void {

int t; while(m

*s, int

fun(int

m, int n)

{t=s[m]; s[m]=s[n]; s[n]=t; m++; n--;} } main() {

Int a[5]={1,2,3,4,5},k; fun(a,0,4);

for(k=0;k<5;k++) printf(\ }

6.

int fun(char s[]) {

int n=0;

while(*s<='9'&&*s>='0') {

n=10*n+*s-'0';

s++;

}

return(n); } main() {

char s[10]={'6','1','*','4','*','9','*','0','*'}; printf(\ }

7.

#include {

int y;

if(x==0||x==1) y=x*x-fun(x-2) return } main() {

int x,y;

y;

return(3);

Int fun(int x)

\

x=fun(3); y=fun(4);

printf(\ }

8.

fun(int n,int *s) {

int f1, f2;

if(n==1 || n==2) else {

fun(n-1, &f1); fun(n-2, &f2); *s=f1+f2; } } main() {

int x; fun(6,&x); printf(\ }

*s=1;

三、填空题

1. 以下程序实现了计算 x 的 n 次方,请将程序填写完整。

float power(float x,int n)

{ int i; float t=1;

for(i=1;i<=n;i++)

t=t*x;

【 1 】 ; } main( ) {float x,y; int

n;

scanf(\ y=power(x,n); printf(\

}

2.

以下程序实现了求两个数的最大公约数,请将程序填写完整。

int divisor(int a,int b) { int r; r=a%b;

while( 【 2 】 )

{ a=b;b=r;r=a%b;} return b;

}

void main() { int a,b,d,t;

scanf(\ if (a

{ t=a; a=b; b=t; } d=divisor(a,b); printf(\ }

3. 以下函数 my_cmp( )的功能是比较字符串 s 和 t 的大小,当 s 等于 t 时返回 0,否则返

回 s 和 t 的第一个不同字符的 ASCII 码差值,即 s

>>閻忕偞娲栫槐鎴﹀礂閵婏附鐎�<<
12@gma联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4