问答题下列给定程序中函数fun的功能是:将tt所指字符串中的小写字母全部改为对应的大写字母,其他字符不变。例如,若输入“Ab,cD”,则输出“AB,CD”。请改正程序中的错误,使它能得出正确的结果。注意:部分源程序在文件MOD11.C中,不得增行或删行,也不得更改程序的结构!#include<stdio.h>#include<string.h>char*fun(char tt[]){int i;for(i=0;tt[i];i++)/**********found**********/if(('a'<=tt[i])‖(tt[i]<='z'))/**********found**********/tt[i]+=32;return(tt);}main(){char tt[81];printf(''\nPlease enter a str:ng:'');gets(tt);printf(''\nThe result string is:\n%s'',fun(tt));}
问答题编写函数fun,其功能是:根据以下公式求π的值(要求精度0.0005,即某项小于0.0005时停止迭代)。程序运行后,若输入精度0.0005,则程序应输出为3.14…。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdio.h>#include<conio.h>#include<math.h>doublefun(doubleeps){}voidmain(){doublex;printf("Inputeps:");Scanf("%lf",printf("/neps=%lf,PI=%lf/n",x,fun(x));}
问答题下列给定程序中函数fun的功能是:从整数1~55,查找能被3整除且有一位上的数值是5的数,把这些数放在b所指的数组中,这些数的个数作为函数值返回。规定函数中a1放个位数,a2放十位数。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动mam函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include <stdio.h> int fun(int *b) int k, a1, a2, i=0; for(k=10; k<=55; k++) /******************found*******************/ a2=k/10; a1=k-a2*10; if((k%3==0&& a2==5)||(k%3==0&& a1==5)) b[i]=k; i++; /******************found*******************/ return k; main() int a[100], k, m; m=fun(a); printf("The result is:/n"); for(k=0; k<m; k++) printf("%4d", a[k]); printf("/n");
问答题下列程序定义了N×N的二维数组,并在主函数中赋值。请编写函数fun,函数的功能是:求出数组周边元素的平均值并作为函数值返回给主函数中的s。例如,若a数组中的值为:0 1 2 7 91 9 7 4 52 3 8 3 14 5 6 8 25 9 1 4 1则返回主程序后s的值应为3.375。注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。试题程序:1 #include<stdio.h>2 #include<conio.h>3 #include<Stdlib.h>4 #define N 55 double fun(int w[][N])6 {78 }9 void main()10 {11 FILE*wf;12 int a[N][N]={0,1,2,7,9,1,9,7,4,5,2,3,8,3,1,4,5,6,8,2,5,9,1,4,1);13 int i,j;14 double s;15 system("CLS");16 printf("***The array***\n");17 for(i=0;i<N;i++)18 { for (j=0;j<N;j++)19 { printf("%4d",a[i][j]);)20 print:f("\n");21 }22 s=fun(a);23 printf("***THE RESULT***\n");24 printf("The sum is:%lf\n",s);25 /*****************/26 wf=fopen("out.dat","w");27 fprintf(wf,"%lf",s);28 fclose(wf);29 /*****************/30 }
问答题给定程序中,函数fun的功能是用函数指针指向要调用的函数,并进行调用。规定在__2__处使fa指向函数f1,在__3__处使fb指向函数f2。当调用正确时,程序输出: x1=5.000000,x2=3.000000,x1*x1+x1*x2=40.000000 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 double f1(double x)3 { return x *x;}4 double f2(double x,double y)5 { return x*y;)6 double fun(double a,double b)7 {8 /**********found**********/9 __1__(*f)();10 double r1,r2;11 /**********found**********/12 f=__2__;/* point fountion f1 */13 r1=f(a);14 /**********found**********/15 f=__3__;/* point fountion f2 */16 r2=(*f)(a,b);17 return r1+r2;18 }19 main()20 {double x1=5,x2=3,r;21 r=fun(x1,x2);22 printf(''\nx1=%f,x2=%f,x1*x1+ x1*x2=%f\n'',x1,x2,r);23 }
问答题给定程序中,函数fun的功能是:求ss所指字符串数组中长度最短的字符串所在的行下标,作为函数值返回,并把其串长放在形参n所指变量中。ss所指字符串数组中共有M个字符串,且串长<N。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在
下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include <stdio.h>
#include <string.h>
#define M 5
#define N 20
int fun(char (*ss) [N], int *n)
{ int i, k=0, len=N;
/**********found**********/
for(i=0; i<______; i++)
{ len=strlen(ss[i]);
if(i==0) *n=len;
/*********found**********/
if (len ______ *n)
{ *n=len;
k=i;
}
}
/*********found**********/
return (______);
}
main()
{ char ss[M] [N]={"shanghai","guangzhou","beijing","tianjing","chongqing"};
int n,k,i;
printf("/nThe original strings are :/n");
for(i=0;i<M;i++)puts(ss[i]);
k=fun(ss,
printf("/nThe length of shortest string is:%d/n",n);
printf("/nThe shortest string is:%s/n",ss[k]);
}
问答题请编写函数fun,该函数的功能是:统计各年龄段的人数。N个年龄通过调用随机函数获得,并放入主函数的age数组中。要求函数把0一9岁年龄段的人数放在d[0]中,把10 N19岁年龄段的人数放在d[1]中,把20一29岁年龄段的人数放在d[2]中,依此类推,把100岁(含100岁)以上年龄的人数都放在d[10]中。结果在主函数中输出。 注意:部分源程序在文件PROG1.C中。 请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序:#include < stdio.h ># define N 50 # de fine,M 11void fun (int *a, int *b) {double rnd () { static t =29,c =217,m =1024,r =0; return ((double) r/m) ,* }void main ( ) { FILE * wf, int age[N], i,d[M] ; int b[N] = {32,45,15,12,86,49, 97,3,44,52,17,95,63 }; age[i] = (int) (115 * rnd ()); printf ("The original data :/n") ;4d",age[i]) ; / *每行输出10个数*/ printf ( "/n/n") ; fun (age,d) ; for (1 =0; i < 10; 1++) printf ("% 4d 一一一%4d :%4d/n", i*l0, 1*10 +9,d[i]) ; printf ("Over 100 : %4d/n",d[10]);/******************/ wf = fopen ("out.dat","w") ; fun (b,d) ; for (i=0; 1 < 10; 1++) fprintf (wf,"%4d—o04d :%4d/n", i fprintf (wf,"Over 100 : %4d",d[10] ) ; fclose (wf) ;/******************/ }
问答题下列给定程序中,函数fun的功能是:计算并输出下列级数的前N项和SN,直到SN+1的值大于q为止,g的值通过形参传入。例如,若q的值为50.0,则函数值应为49.394948。请改正程序中的错误,使它能得出正确的结果。注意:不要改动mmn函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<conio.h>#include<stdio.h>doublefun(doubleq){intn;doubles,t;n=2;s=2.0;while(s<=q){t=s;/*********found*********/s=s+(n+1)/n;n++;}printf("n=%d/n",n);/*********found*********/returns;}main(){printf("%f/n",fun(50));}
问答题给定程序的功能是:计算并输出下列级数的前n项之和Sn,直到Sn大于q为止,q的值通过形参传入。例如,若q的值为50.0,则函数值为50.416687。注意:部分源程序给出如下。请勿改动主函数main()和其他函数中的任何内容,仅在函数fun()的标号处填入你编写的若干表达式或语句。试题程序#include<stdio.h>doublefun(doubleq){intn;doubles;n=2;s=2.0;while(s______q){s=s+______(n+1)/n;______;}printf("n=%d/n",n);returns;}main(){printf("%f/n",fun(50));}
问答题请编写函数fun,函数的功能是求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。 例如:二维数组中的值为: 1 3 5 7 9 2 9 9 9 4 6 9 9 9 8 1 3 5 7 0 则函数值为61。 注意:部分源程序存在文件PROG1.C文件中。 请勿改动主函数mare和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。l #include<stdio.h>2 #define M 43 #define N 54 int fun(int a[M][N])5 {67 }8 main()9 { Int aa[M][N]={{1,3,5,7,9},{2,9,9,9,4},{6,9,9,9,8},{1,3,5,7,0}};10 int i,j,y;void NONO();11 printf(''The original data is:\n'');12 for(i=0;i<M; i++)13 { for(j=0;j<N;j++)printf(''%6d'',aa[i][j]);14 printf(''\n'');15 }16 y=fun(aa);17 printf(''\nThe sum:%d\n'',y);18 printf(''\n'');19 NONO( );20 }21 void NONO( )22 {/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/23 int i,j,y,k,aa[M][N];24 FILE *rf,*wf;25 rf=fopen(''in.dat'',''r'');26 wf=fopen(''out.dat'',''w'');27 for(k=0;k<10;k++){28 for(i=0;i<M;i++)29 for(j=0;j<N;j++)fscanf(rf,''%d'',32 }33 fclose(rf);34 fclose(wf);35 }
问答题给定程序modi1.c的主函数中,将a、b、c三个结点链成一个单向链表,并给各结点的数据域赋值,函数fun()的作用是:累加链表结点数据域中的数据作为函数值返回。
请改正函数fun中指定部位的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdio.h>
typedef struct list
{int data;
struct list*next;
}LIST;
int fun(LIST*h)
{LIST*p;
/**********found**********/
int t;
p=h;
/**********found**********/
while(*p)
{
/**********found**********/
t=t+p.data;
p=(*p).next;
}
return t;
}
main()
{LIST a,b,c,*h;
A.data=34;b.data=51;c.data=87;c.next="/0";
h=A)next=b.next=
printf("总和=%d/n",fun(h));
}
问答题请编写一个函数proc(),它的功能是:将str所指字符串中所有下标为奇数位置的字母转换为大写(若该位置上不是字母,则不转换)。
例如,若输入abcde123,则应输出aBcDe123。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void proc(char*str)
{
}
void main()
{
char tt[81];
system("CLS");
printf("/nPlease enter an string within80 characters:/n");
gets(tt);
printf("/n/nAfter changing,the string
/n%s",tt);
proc(tt);
printf("/nbecomes/n%s/n",tt);
}
问答题下列给定程序中,函数fun的功能是进行数字字符转换。若形参ch中是数字字符‘0’~‘9’,则将‘0’转换成‘9’,‘1’转换成‘8’,‘2’转换成‘7’,…,‘9’转换成‘0’;若是其他字符则保持不变,并将转换后的结果作为函数值返回。 请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #include<stdio.h> /********found********/ (1) fun(char ch) /********found********/ if(ch>='0' return ch; main() (char c1,c2; printf("/nThe result:/n")" c1='2';c2=fun(c1); printf("c1=%c c2=%c/n",c1,c2); c1='8';c2=fun(c1); printf("c1=%c c2=%c/n",c1,c2); c1='a';c2=fun(c1); printf("c1=%c c2=%c/n",c1,c2);
问答题规定输入的字符串中只包含字母和*号。编写函数fun,其功能是:删除字符串中所有的*号。编写函数时,不得使用C语言提供的字符串函数。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序: #include<stdio.h> void fun(char *a) void main() char s[81]; printf("Enter a string:/n"); gets(s); fun(s); printf("The string after deleted:/n"); puts(s);
问答题编写一个函数,从传入的M个字符中找出最长的一个字符串,并通过形参指针max传回该串地址(用****作为结束输入的标志)。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#include<string.h>
#include<conio.h>
char*proc(char(*a)[81],int num)
{
}
void main()
{
char ss[10][81],*max;
int n,i=0;
printf("输入若干个字符串:");
gets(ss[i]);
puts(ss[i]);
while(!strcmp(ss[i],"****")==0)
{
i++;
gets(ss[i]);
puts(ss[i]);
n=i;
max=proc(ss,n);
printf("/nmax=%s/n",max);
}
问答题给定程序MODI1.C中函数fun的功能是:求整数x的y次方的低3位值。例如,整数5的6次方为15625,此值的低3位值为625。
请改正函数fun中指定部位的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
#include
long fun(int x,int y,long *p)
{ int i;
long t=l;
/************found************/
for(i=l; i
问答题printf("%d, %d/n ", k, a[k]);
问答题假定输入的字符串中只包含字母和*号。请编写函数 fun(),它的功能是:使字符串中前部的*号不得多余n个;若多余n个,则删除多余的*号;若少于或等于n个,则什么也不做,字符串中间和尾部的*号不删除。 例如,字符串中的内容为****A*BC*DEF*G*******,若 n的值为2,删除后,字符串中的内容则应当是 **A*BC*DEF*G*******;若n的值为4,则字符串中的内容仍为****A*BC*DEF*G******。n的值在主函数中输入。在编写函数时,不得使用C语言提供的字符串函数。 注意:部分源程序给出如下。 请勿改动主函数main 和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。 试题程序: #include <stdio.h> #include <conio.h> void fun (char Aa, int n) main () char s[81];int n; printf ("Enter a string : /n") ;gets (s); printf ("Enter n : "); scanf ("%d", fun( s,n ); printf("The string after deleted :/n"); puts (s);
问答题学生的记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组s中。请编写函数fun,其功能是:把指定分数范围内的学生数据放在b所指的数组中,分数范围内的学生人数由函数值返回。例如,输入的分数是60、69,则应当把分数在60—69的学生数据输出,包含60分和69分的学生数据。主函数中把60放在low中,把69放在heigh中。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdio.h>#define N 1 6 typedef struct{ char num[1 0]; int s;}STREC;int fun(STREC*a,STREC*b,int 1,int h){}void main(){ STREC s[N]={{"GA005",85},{"GA003",76),{"GA002",69},{"GA004",85),{"GA001",96},{"GA007",72},{"GA008",64},{"GA006",87},{"GA015",85},{"GA013",94},{"GA012",64},{"GA014",91},{"GA011",90},{"GA017",64},{"GA018",64},{"GA016",72}}; STREC h[N]; int i,n,low,heigh,t; printf("Enter 2 integer number low&heigh:"); scanf("%d%d",&low,&heigh); if(heigh<low) {t=heigh;heigh=low;low=t;} n=fun(s,h,low,heigh); printf("The student's data between %d--%d:\n",low,heigh); for(i=0;i<n;i++) printf("%s%4d\n",h[i].num,h[i].s); printf("\n");}
问答题编写函数fun,其功能是:将a、b中的两个两位正整数合并成一个新的整数放在c中。合并的方式是:将a中的十位和个位数依次放在变量c的百位和个位上,b中的十位和个位数依次放在变量c的十位和千位上。
例如,当a=45,b=12,调用该函数后c=2415。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<conio.h>
#include<stdio.h>
void fun(int a, int b, long*c)
{
}
main()
{
int a, b;
long c;
printf("Input a, b;");
scanf("%d%d",
fun(a, b,
printf("The result is:%ld/n", c);
}
