问答题 请编一个函数fun(oh lr*str),该函数的功能是把字符串中的内容逆置。 例如,字符串中原有的字符串为asdf9,则调用该函数后,串中的内容为9fdsa。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填人所编写的若干语句。 试题程序: #include<string.h> #include<conio.h> #include<stdio.h> #define N 100 void fun(char * str) {} void main() { char a[N]; FILE*out: printf("Enter a string:"); gets(a); printf("The origir al string is:"); puts(a); fun(a): printf("The string after modified:"); puts(a); strcpy(a,"Welcome!"); fun(a); out=fopen("outfile.dat","w"); fprintf(out,"%s".a); fclose(out); }
问答题 请编写fun()函数,其功能是:计算并输出3~m所有素数的平方根之和。 例如,若主函数从键盘给m输入50后,则输出为s= 68.665791。 请勿改动main()函数与其他函数中的任何内容,仅在函数fun()的花括号中填入所编写的若干语句。 注意:m的值要大于2但不大于100。部分源程序给出如下。 试题程序: #include<math.h> #include<stdio.h> double fun(int m) {} void main() { int m; double s; FILE*out: printf("\n\nInput m:"); scanf("%d",&m); s=fun(m); printf("\n\ns=%f\n\n",s); out=fopen("outfile.dat","w"); for(m=0;m<10;m++) fprintf(out,"%f\n",fun(m+80)); felose(out); }
问答题 已知一个数列从0项开始的前3项为0,0,1,以后的各项都是其相邻的前3项之和。下列给定的程序中,函数proc ()的功能是:计算并输出该数列前n项的和sum。n的值通过形参传人。例如,当n=20时,程序的输出结果应为42762.000000。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动maiil()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include<stdlib.h> #include<conio.h> #include<stdio.h> double proc(int n) { double sum,s0,s1,s2,s; int k; sum=1.0; if(n<=2) sum=0.0; s0=0.0; s1=0.0; s2=1.0; //****found**** for(k=4;k<n;k++) } { s=s0+s1+s2; sum+=S: s0=s1; s1=s2; //****found**** s2=s; return sum; } void main() { int n; system("CLS"); printf("Input N="); scanf("%d",&n J; printf("%f\n",proc(n)); }