函数void fun(float *sn, int n)有功能是根据以下公式计算S,计算结果通过形参指针sn传回,n通过形参传入,n的值大于等于0.请填空。S = 1- 1/3 +1/5 - 1/7 + ......1/(2n-1)void fun(float *sn, int n){float s = 0.0, w, f = -1.0;int i = 0;for(i = 0; i <= n; i++){f = () * f;w = f / (2 * i + 1); s += w;}() = s;}
查看答案
下列程序中huiwen()函数的功能是检查一个字符串是否回文。当字符串是回文时,函数返回字符串“yes!”,否则返回“no!”,并在主函数中输出。所谓回文即正向和反向的拼写都一样,例如“adgda”。请填空。char *huiwen(char *str){char *p1, *p2; int i, t = 0;p1 = str; p2 = ();for(i = 0; i <= strlen(str) / 2; i++)if(*p1++ != *p2--) { t = 1; break; }if() return("yes!");else return("no!");}int main(void){char str[50];printf("Input:"); scanf("%s",str);printf("%s\n",());return 0;}
下列程序中的函数strcpy2( )实现字符串两次复制,即将t所指字符串复制两次到s所指内存空间中,合并形成一个新字符串。例如:若t所指字符串为“efgh”,调用strcpy2后,s所指字符串为 “efghefgh”。请填空。void strcpy2(char *s, char *t){char *p = t;while(*s++ = *t++);s = ();while( () = *p++);}int main(void){char str1[100] = "abcd" , str2[ ] = "efgh";strcpy2(str1,str2); printf("%s\n", str1);return 0;}
下列程序运行时如果从键盘输入字符串“qwerty”和“abcd”,则程序的输出结果是( )。int strle(char a[ ], char b[ ]){int num = 0,n = 0;while(*(a+num) != '\0') num++;while(b[n]) { *(a+num) = b[n]; n++; }return(num);}int main(void){char str1[81] , str2[81], *p1 = str1, *p2 = str2;gets(p1); gets(p2);printf("%d\n", strle(p1, p2)); return 0;}
阅读下列程序并回答问题。void funstr(char p[ ], char q[ ],int m){int k = strlen(q);for(;p[m] != '\0'; m++)q[m] = p[m]; /*第4行* /q[m] = '/0';}int main(void){char a[100] = "theVisualc++";char b[100] = "6.0";int m;scanf("%d", &m);funstr(a, b, m);puts(b); return 0;}(1) 程序运行时,输入3,输出();输入5,输出()。(2)将第4行改为“q[m-k] = p[m];”,程序运行时,输入3,输出()。