给定程序中,函数fun的功能是:将形参n中,各位上为偶数的数取出,并按原来从高位到低位相反的顺序组成一个新的数,并作为函数值的返回。
- 例如,输入一个整数:27638496,函数返回的值为:64862
1
2
3
4
5
6
7
8
9
10
11
12
13unsigned long fun(unsigned long n)
{ unsigned long x=0; int t;
while(n)
{ t=n%10;
/**********found**********/
if(t%2==0)
/**********found**********/
x=10*x+t;
/**********found**********/
n=n/10;
}
return x;
}给定程序中,函数fun的功能是:将形参指针n所指变量中,各位上位偶数的数去除,剩余的数按原来从高位到低位的顺序组成一个新序列,并通过形参指针n传回所指变量。
1
2
3
4
5
6
7
8
9
10
11
12
13
14void fun(unsigned long *n)
{ unsigned long x=0, i; int t;
i=1;
while(*n)
/**********found**********/
{ t=*n % 10;
/**********found**********/
if(t%2!= 0)
{ x=x+t*i; i=i*10; }
*n =*n /10;
}
/**********found**********/
*n=x;
}给定程序中,函数fun的功能是:计算下面值
$$s=\frac{1\times3}{2^2}+\frac{3\times5}{4^2}+…+\frac{(2\times {n}-1)\times(2\times+1)}{(2\times n)^2}$$1
2
3
4
5
6
7
8
9
10
11
12double fun(int n)
{ int i; double s, t;
/**********found**********/
s=0;
/**********found**********/
for(i=1; i<=n; i++)
{ t=2.0*i;
/**********found**********/
s=s+(2.0*i-1)*(2.0*i+1)/(t*t);
}
return s;
}
给定程序中,函数fun的功能是:计算下面值
$$s=\frac{1\times3}{2^2}-\frac{3\times5}{4^2}-…+(-1)^{n-1}\frac{(2\times n-1)\times(2\times+1)}{(2\times n)^2}$$1
2
3
4
5
6
7
8
9
10
11
12
13
14double fun(int n)
{ int i, k; double s, t;
s=0;
/**********found**********/
k=1;
for(i=1; i<=n; i++) {
/**********found**********/
t=2.0*i;
s=s+k*(2*i-1)*(2*i+1)/(t*t);
/**********found**********/
k=k*-1;
}
return s;
}
给定程序中,函数fun的功能是:计算下面值
$$s=\frac{3}{2^2}-\frac{5}{4^2}+\frac{7}{6^2}-…+(-1)^{n-1}\frac{2\times n+1}{2\times n}^2$$1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16double fun(double e)
{ int i, k; double s, t, x;
s=0; k=1; i=2;
/**********found**********/
x=3.0/4;
/**********found**********/
while(x > e)
{ s=s+k*x;
k=k* (-1);
t=2*i;
/**********found**********/
x=(2*i+1)/(t*t);
i++;
}
return s;
}给定程序中,函数fun的功能是:将形参s所指字符串中的所有的字母字符顺序前移,其他字符顺序后移,处理后新字符串的首地址作为函数的返回值
- 例如:s所指的字符串为asd123fgh543df,处理后新字符串为asdfgh123543.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19char *fun(char *s)
{ int i, j, k, n; char *p, *t;
n=strlen(s)+1;
t=(char*)malloc(n*sizeof(char));
p=(char*)malloc(n*sizeof(char));
j=0; k=0;
for(i=0; i<n; i++)
{ if(((s[i]>='a')&&(s[i]<='z'))||((s[i]>='A')&&(s[i]<='Z'))) {
/**********found**********/
t[j]=s[i]; j++;}
else
{ p[k]=s[i]; k++; }
}
/**********found**********/
for(i=0; i<k; i++) t[j+i]=p[i];
/**********found**********/
t[j+k]= '\0';
return t;
}
给定程序中,函数fun的功能是:将形参s所指字符串中的所有的字符顺序前移,其他字符顺序后移,处理后新字符串的首地址作为函数的数字返回值
- 例如:s所指的字符串为asd123fgh543df,处理后新字符串为123543asdfgh.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
char *fun(char *s)
{ int i, j, k, n; char *p, *t;
n=strlen(s)+1;
t=(char*)malloc(n*sizeof(char));
p=(char*)malloc(n*sizeof(char));
j=0; k=0;
for(i=0; i<n; i++)
{ if(isdigit(s[i])) {
/**********found**********/
p[j]=s[i]; j++;}
else
{ t[k]=s[i]; k++; }
}
/**********found**********/
for(i=0; i<k; i++) p[j+i]= t[i];
p[j+k]=0;
/**********found**********/
return p;
}