问答题请编写函数fun,它的功能是:求出能整除形参x且不是偶数的各整数,并按从小到大的顺序放在pp所指的数组中,这些除数的个数通过形参n返回。
例如,若 x 中的值为: 35,则有 4 个数符合要求,它们是: 1, 5, 7, 35。
注意: 部分源程序在文件PROG1.C文件中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
void fun ( int x, int pp[], int *n )
{
}
main( )
{ int x, aa[1000], n, i ;
printf( "/nPlease enter an integer number:/n" ) ; scanf("%d",
fun(x, aa,
for( i = 0 ; i < n ; i++ )
printf("%d ", aa[i]) ;
printf("/n") ;
NONO( ) ;
}
问答题请编写函数fun,其功能是:计算并输出下列多项式的值。例如,当n=10时,函数值为0.909091。注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<conio.h>#include<stdio.h>#include<stdlib.h>doublefun(intn){}voidmain(){FILE*wf;system("CLS"),printf("%f/n",fun(10));/*********found*********/wf=fopen("out.dat","w");fprintf(wf,"%f",fun(10));fclose(wf);/*********found*********/}
问答题
已知学生的记录由学号和学习成绩构成,N名学生的数据己存入结构体数组a中。请编写函数fun,函数的功能是:找出成绩最高的学生记录,通过形参指针传回主函数(规定只有一个最高分)。已给出函数的首部,请完成该函数。
注意:部分源程序存在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#inolude<stdio.h>
#include<string.h>
#define N 10
typedef struct ss
{char num[10]; int s;} STU;
fun(STU a[], STU *s)
{
}
main()
{STU a[N]={{"A01", 81}, {"A02", 89},
{"A03", 66}, {"A04", 87}, {"A05", 77},
{"A06", 90}, {"A07", 79}, {"A08", 61},
{"A09", 80}, {"A10", 71}}, m;
int i;
printf("*****The original data *****/n");
for(i=0; i<N; i++)printf("No= %s Mark = %d/n", a[i].num, a[i].s);
fun(a,
printf ("*****THE RESULT *****/n");
printf("The top:%s, %d/n", m.num, m.s);
NONO();
}
NONO()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
FILE *rf, *wf;
STU a[N], m;
int i;
rf=fopen("in.dat", "r");
wf=fopen("out.dat", "w");
for(i=0; i<10; i++)fscanf(rf, "%s%d", a[i].num,
fun(a,
fprintf(wf, "The top:%s, %d/n", m.num, m.s);
fclose(rf);
felose(wf);
}
问答题下列给定程序中,函数fun()的功能是:将tt所指字符串中的小写字母全部改为对应的大写字母,其他字符不变。
例如,若输入“Ab,cD”,则输出“AB,CD”。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<conio.h>
#include<stdio.h>
#include<string.h>
char*fun(char tt[])
{
int i;
for(i=0; tt[i]; i++)
//****found****
if((tt[i]>="a")||(tt[i]<="z"))
//****found****
tt[i]+=32;
return(tt);
}
void main()
{
char tt[81];
printf("/nPlease enter a string: ");
gets(tt);
printf("/nThe result string is: %s/n", fun(tt));
}
问答题下列给定程序中,函数fun的功能是:求ss所指字符串数组中长度最短的字符串所在的行下标,作为函数值返回,并把其串长放在形参n所指的变量中。ss所指字符串数组中共有M个字符串,且串长小于N。
请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#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<
【1】
;i++)
{ fen=strlen(ss[i]);
if(i==0) *n=len;
/*********found*********/
if(len
【2】
*n)
{*n=len;
k=i;
}
}
/*********found*********/
return(
【3】
);
}
main()
{ char ss.[M][N]={" shang hai","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,&n);
printf("\nThe length of shortest string is:%d\n",n);
printf("\nThe shortest string is:%s\n",ss[k]);
}
问答题请编写函数fun,函数的功能是:统计一行字符串中单词的个数,作为函数值返回。一行字符串在主函数中输入,规定所有单词由小写字母组成,单词之间由若干个空格隔开,一行的开始没有空格。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数mam和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include
#include
#define N 80
int fun (char *s)
{
}
main()
{char line[N];int num=0; void NONO();
printf( "Enter a string :/n");
gets (line);
num=fun (line);
printf( "The number of word
is : %d/n/n",num);
NONO();
)
void NONO ()
{/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。 */
FILE *—rf,*wf; int i, num; charline [N], *p;
rf — fopen("in.dat","r");
wf — fopen ("out.dat","w");
for(i= 0 ; i< 10 ; i++) {
fgets (line, N, rf);
p = strchr (line, '/n');
if(p !=NULL) *p =0 ;
riurci=fun (line);
fprintf (wf,"%d/n", num);
}
fclose (rf), fclose (wf),
}
问答题写出下列程序的运行结果。
#include “stdio.h”
Main()
{ int a[]={1,2,3,-4,5};
int m,n,*p; p= m=*(p+1); n=*(p+4);
printf(“%d %d %d ”,*p,m,n); }
问答题给定程序MODI1.C中函数fun的功能是:对N名学生的学习成绩,按从高到低的顺序找出前m(m≤10)名学生来,并将这些学生数据存放在一个动态分配的连续存储区中,此存储区的首地址作为函数值返回。 请改正函数fun中指定部位的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 #include<stdlib.h>3 #include<string.h>4 #define N 105 typedef struct ss6 { char num[10];7 int s;8 } STU;9 STU *fun(STU a[],int m)10 { STU b[N],*t;11 int i,j,k;12 /**********found**********/13 t=(STU *)calloc(sizeof(STU),m)14 for(i=0;i<N;i++)b[i]=a[i];15 for(k=0;k<m;k++)16 { for(i=j=0;i<N;i++)17 if(b[i].s>b[j].s) j=i ;18 /**********found**********/19 t(k)=b(j);20 b[j].s=0;21 }22 return t;23 }24 outresult(STU a[],FILE *pf)25 { int i;26 for(i=0;i<N;i++)27 fprintf(pf,''No=%s Mark=%d\n'',a[i].num,a[i].s);28 fprintf(pf,''\n\n'');29 }30 main()31 { STU a[N]={{''A01'',81},{''A02'',89},{''A03'',66},{''A04'',87},{''A05'',77},{''A06'',90},{''A07'',79},{''A08'',61},{''A09'',80},{''A10'',71}};32 STU *pOrder;33 int i,m;34 printf(''*****The Original data*****\n'');35 outresult(a,stdout);36 printf(''\nGive the number of the students who have better score:'');37 scanf(''%d'',&m);38 while(m>10)39 { printf(''\nGive the number of the students who have better score:'');40 scanf(''%d'',&m);41 }42 porder=fun(a,m);43 printf(''***** THE RESULT ***** \n'');44 printf(''The top:\n'');45 for(i=0;i<m;i++)46 printf(''%s%d\n'',pOrder[i].num,pOrder[i].s);47 free(pOrder);48 }
问答题请编写函数fun,其功能是:找出2×M整型二维数组中最大元素的值,并将此值返回调用函数。 注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序:#include<stdio.h>#define M 4 int fun(int a[][M]){}main(){ int 8rr[2][M]={5,8,3,45,76,一4,12,82}; void NONO(); prinff(“max=%d\n”,fun(arr)); NONO();}void NONO()/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/{ FILE* wf; int alT[][M]={5,8,3,90,76,一4,12,82}; wf=fopen(“out.dat”,“W”);fprintf(wf,“inax=%d\n”,fun(arr));fclose(wf);}
问答题学生的记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组s中。请编写函数fun,其功能是:把指定分数范围内的学生数据放在b所指的数组中,分数范围内的学生人数由函数值返回。
例如,输入的分数是60、69,则应当把分数在60~69的学生数据输出,包含60分和69分的学生数据。主函数中把60放在low中,把69放在heigh中。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#define N 16
typedef struct
{
char num[10];
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},{"GA0l7",64},{"GA018",64},{"GA016",72}};
STREC h[N];
int i,n,low,heigh,t;
printf("Enter 2 integer number low
scanf("%d%d",
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的功能是将不带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在
下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
#include <stdio.h>
#include <stdlib.h>
#define N 5
typedef struct node {
int data;
struct node *next;
} NODE;
/***********found*********/
______ fun (NODE *h)
{NODE *p, *q, *r;
p=h;
if (p==NULL)
return NULL;
q=p->next;
p->next=NULL;
while (q)
{
/**********found**********/
r=q->______;
q->next=p;
p=q;
/**********found**********/
q=______;
}
return p;
}
NODE *creatlist(int a[])
{NODE *h,*p,*q; int i;
h=NULL;
for(i=0; i<N; i++)
{ q=(NODE *)malloc(sizeof (NODE);
q->data=a[i];
q->next=NULL;
if (h==NULL) h=p=q;
else {p->next=q; p=q;}
}
return h;
}
void outlist(NODE *h)
{NODE *p;
p=h;
if (p==NULL) printf("The list is NULL!/n");
else
{ printf("/nHead");
do
{ printf("->%d", p->data); p=p->next;}
while(p!=NULL);
printf("->End/n");
}
}
main()
{NODE *head;
int a[N]={2,4,6,8,10};
head=creatlist(a);
printf("/nThe original list:/n");
outlist(head);
head=fun(head);
printf("/nThe list after inverting:/n");
outlist(head);
}
问答题简单应用
给定程序MODI1.C中,函数fun的功能是:在有n名学生,2门课成绩的结构体数组std中,计算出第1门课程的平均分,作为函数值返回。例如,主函数中给出了4名学生的数据,则程序运行的结果为:第1门课程的平均分是:76.125000
请改正函数fun中指定部位的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
#include
typedef struct
{ char num[8];
double score[2];
}STU ;
double fun(STU std[], int n)
{ int i;
/**********found**********/
double sum ;
/**********found**********/
for(i=0; i<2 ; i++)
/**********found**********/
sum += std[i].score[1];
return sum/n;
}
main()
{ STU std[ ]={ "N1001", 76.5,82.0 ,"N1002", 66.5,73.0,
"N1005", 80.5,66.0,"N1006", 81.0,56.0 };
printf("第1门课程的平均分是:%lf/n", fun(std,4) );
}
问答题学生记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组中,请编写函数fun,其功能是:把分数最低的学生数据放入b所指的数组中。注意:分数最低的学生可能不止一个,函数返回分数最低的学生人数。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include <stdio.h>
#deftne N 16
typedef struct
{char num[10];
int s;
}STREC;
mt fun( STREC * a, STREC * b )
{
}
main( )
{ STREC s[N] = {{"GA05" ,85 }, {"GA03" ,76}, {"GA02",69}, {"GA04",85},
{"GA01",91},{"GA07",72},{"GA08",64},{"GA06",87},
{"GA015",85}, {"GA013",91},{"GA012",64}, {" GA014",91/,
{"GA011",91}, {"GA017",64},{"GA018",64},{"GA016",72t}};
STREC h[N];
int i,n; FILE * out;
n=fun(s,h);
printf("The % d lowest score :/n",n);
for(i=0;i<n; i+ +)
printf("% s %4d/n", h[i]. num,h[i].s);
printf(" /n");
out=fopen("out.dat","w");
fprintf(out,"% d/n",n);
for(i=0;i<n;i+ +)
fprintf(out,"%4d/n",h[i].s);
fclose (out);
}
问答题函数fun的功能是进行数字字符转换。若形参ch中是数字字符"0"~"9",则"0"转换成"9","1"转换成"8","2"转换成"7",……,"9"转换成"0";若是其他字符则保持不变;并将转换后的结果作为函数值返回。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在
下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include <stdio.h>
/**********found**********/
______ 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的功能是:将存放学生数据的结构体数组,按姓名的字典序(从小到大)排序。
请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include < stdio.h >
#include < string.h >
struct student{
long sno;
char F1&me[10];
float score[3];
};
void fun(struct student a[],int n)
{
/*********found*********/
【1】
t;
int i,j;
/*********found*********/
for(i=0;i <
【2】
;i++)
for(j=i+1; j < n;j++)
/*********found*********/
if(strcmp(
【3】
) >0)
{t=a[i];a[i]=a[j];
a[j]=t;
}
}
main()
{ struct student s[4]=
({10001,"ZhangSan",95,80,88},
{10002,"LiSi",85,70,78},
{10003,"CaoKai",75,60,88},
{10004,"FangFang",90,82,87)};
int i,j;
printf,"/n/ nThe original
data:/n/n");
for(j=0;j < 4;j++)
{printf("/nNo:%ld Name:
%一8sscor.es:",s[j].sno,s[j].
name);
for(i=0;i < 3;i++)
printf("%6.2 f",
s[j].score[i]);
printf("/n");
}
fun(s,4);
printf ("/n/nThe data after
sorting:/n/n");
for(j=0;j < 4;j++)
{printf("/nNo:%ld Name:%一8sscores:",s[j].sno,s[j].
name);
for(i=0;i < 3;i++)
printf("%6.2f",s[j].score[i]);
printf("/n");
}
}
问答题学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:把分数最高的学生数据放在h所指的数组中,注意:分数最高的学生可能不止一个,函数返回分数最高的学生的人数。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。1 #include<stdio.h>2 #define N 163 typedef struct4 { char num[10];5 int s;6 } STREC;7 int fun(STREC *a,STREC *b)8 {910 }11 main()12 { STREC s[N]={{''CA05'',85},{''GA03'',76},{''GA02'',69},{''GA04'',85),{''GA01'',91},{''GA07'',72},{''GA08'',64},{''GA06'',87},{''CA015'',85},{''CA013'',91},{''GA012'',64},{''GA014'',91},{''GA011'',77},{''GA017'',64},{''GA018'',64},{''GA016'',72}};13 STREC h[N];14 int i,n;FILE *out;15 n=fun(s,h);16 printf(''The%d highest score:\n'',n);17 for(2=0;i<n;i++)18 printf(''%s %4d\n'',h[i].num,h [i].s);19 printf(''\n'');20 out=fopen(''out.dat'',''w'');21 fprintf(out,''%d\n'',n);22 for(i=0;i<n; i++)23 fprintf(out,''%4d\n'',h[i].s);24 fclose(out);25 }
问答题请编写函数fun,函数的功能是:统计一行字符串中单词的个数,作为函数值返回。一行字符串在主函数中输入,规定所有单词由小写字母组成,单词之间由若干个空格隔开,一行的开始没有空格。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。1 #include<stdio.h>2 #include<string.h>3 #define N 804 int fun(char *s)5 {67 }8 main()9 { char 1ine[N];int num=0; void NONO();10 printf(''Enter a string:\n'');gets(line);11 num=fun(line);12 printf(''The number of wordis:%d\n\n'',num);13 NONO();14 }15 void NONO()16 {/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/17 FILE *rf,*wf;int i,num;charline[N],*p;18 rf=fopen(''in.dat'',''r'');19 wf=fopen(''out.dat'',''w'');20 for(i=0;i<10;i++){21 fgets(1ine,N,rf);22 p=strchr(1ine,'\n');23 if(p!=NULL) *p=0;24 num=fun(1ine);25 fprintf(wf,''%d\n'',num);26 }27 fclose(rf);fclose(wf);28 }
问答题下列给定程序中,函数fun的功能是:求出如下分数序列的前n项之和,和值通过函数值返回。例如,若n=5,则应输出8.391667。请改正程序中的错误,使其得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<stdlib.h>#include<conio.h>#include<stdio.h>/********found********/voidfun(intn){inta=2,b=1,c,k;doubles=0.0;for(k=1;k<=n;k++){/********found********/s=s+(Double)a/b;c=a;a=a+b;b=c;}returns;}voidmain(){intn=5;system("CLS");printf("/nThevalueoffunctionis:%lf/n",fun(n));}
问答题编写函数fun(),它的功能是求n以内(不包括n)同时能被5与11整除的所有自然数之和的平方根s,并作为函数值返回。 例如:n为1000时,函数值应为s=96.979379。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include <conio.h> #include <math.h> #include <stdio.h> double fun(int n) main() clrscr(); printf("s=%f/n",fun(1000));
问答题规定输入的字符串中只包含字母和*号。编写函数fun,其功能是:删除字符串中所有的*号。编写函数时,不得使用C语言提供的字符串函数。 例如,字符串中的内容为“****A*BC*DEF*G*******”,删除后,字符串中的内容应当是“ABCDEFG”。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序: #include<conio.h> #include<sfdio.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);