问答题学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:
把分数最低的学生数据放在b所指的数组中。
注意:分数最低的学生可能不止一个,函数返回分数最低的学生的人数。
注意:部分源程序在文件PROG1.C文件中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include
#define N 16
typedef struct
{ char num [10] ;
int s;
} STREC;
int fun(STREC *a,STREC *b)
{
}
main ()
{STREC s [N] ={ { "GA05",85},{ "GA03",76},
{ "GA02",69},{ "GA04",85},{ "GA01",91} ,
{ "GA07",72 },{ "GA08",64 },{ "GA06rr,87 } ,
{ "GA015",85},{ "GA013",91} ,{ "GA012",64 },
{ "GA014",91} ,{ "GA011",91} ,{ "GA017",64 },
{"GA018",64},{"GA016",72}};
STREC h [N] ;
int i,n;FILE ;*out ;
n=fun (s,h) ;
printf ("The %d lowest score: /n",n) ;
printf "%s %4d/n",h [i] .num,h [i] .s) ;
out=fopen ("out.dat","w") ;
fprintf (out, "%d/n",n) ;
fprintf (out, "%4d/n",h[i] .s) ;
fclose (out) ;
}
问答题学生的记录由学号和成绩组成,M名学生的数据已在主函数中放入结构体数组stu中,请编写函数proc(),该函数的功能是:把高于等于平均分的学生数据放在b所指的数组中,高于等于平均分的学生人数通过形参n传回,平均分通过函数值返回。 注意:部分源程序已给出。 请勿改动主函数main和其他函数中的任何内容,仅在函数proc的花括号中填入所编写的若干语句。 试题程序: #include<stdio.h> #define M 12 typedef struct char num[10]; double s; STREC; double proc(STREC*a,STREC*b,int*n) void main() STREC stu[M]=f"GA05",85,"GA03",76, "GA02",69),"GA04",85,"GA01",91, "GA07",72),"GA08",64,"GA06",87, "GA09",60,"GA11",79),("GA12",73, "GA10",90; STREC h[M]; int i,n; double ave; ave=proc(stu,h,&n); printf("The%d student data which is higher than %7.3f:/n",n,ave); for(i=0;i<n;i++) printf("%s%4.1f/n",h[i].num,h[i].s); printf("/n");
问答题学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun(),它的功能是:按分数的高低排列学生的记录,高分在前。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在函数fum的花括号中填入所编写的若啡:语句。
试题程序:
#include <stdio.h>
#define N 16
typedef struct
{ char num[10];
int s ;
}STREC;
int fun (STREC a[])
{
}
main ()
{
STREC s IN] ={ {"GA005", 85 }, {"GA003", 76},
{"GA002", 69}, {"GA004", 85}, {"GA001", 91},
{"GA007", 72}, {"GA008", 64}, {"GA006", 87},
{"GA015", 85}, {"GA013", 91}, {"GA012", 64},
{"GA014", 91}, {"GA011", 66}, {"GA017", 64},
{"GA018", 64}, {"GA016", 72} };
int i;
FILE *out;
fun (s);
printf("The data after sorted :In");
for (i=0; i<N; i++)
{if ((i) %4=-0)
/*每行输出4个学生记录*/
printf ("/n");
printf("%s %4d",s[i].num, s[i].s);
}
printf ("/n");
out=fopen ( "out 16. dat", "w" );
for(i=0; i<N; i++);
{if ((i) %4==0
fprintf(out, "%4d",s[i].s);
}
fprintf(out, "/n");
fclose (out);
}
问答题请编写函数fun(),它的功能是:将带头结点单向链表按data域由大小排序(排序时不考虑头结点),主函数用随机函数为各结点data域赋值,头结点data域赋值为0。 注意:部分原程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 [试题源程序] #include <stdio.h> #include <conio.h> struct aa int data; struct aa*next; ; void fun(struct aa*p) main() int i,n,m=100; struct aa*h=NULL,*s=NULL, *p=NULL; clrscr(); S=(struct aa*)malloc(sizeof(struct aa)); h=s;h->data=0;h->next=NULL; printf("Please input n:"); scanf("%d",&n); for(i=1;i<=n;i++) p=(struct aa*)malloc(sizeof(struct aa)); p->data=rand()%m;p->next=NULL; printf("%d",p->data); s->next=p;s=s->next; fun(h); printf("/n"); for(h=h->next;h!=NULL;h=h->nnext) printf("%d",h->data);
问答题
请编写函数fun,函数的功能是:将M行N列的二维数组中的数据,按行的顺序依次放到一维数组中,一维数组中数据的个数存放在形参n所指的存储单元中。
例如,二维数组中的数据为:
33 33 33 33
44 44 44 44
55 55 55 55
则一维数组中的内容应是:
33 33 33 33 44 44 44 44 55 55 55 55。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include<stdio.h>
void fun(int(*s)[10], int *b, int *n, int mm, int nn)
{
}
main()
{int w[10][10]={{33,33,33,33}, {44,44,44,44}, {55,55,55,55}}, i, j;
int a[100]={0}, n=0; void NONO();
printf("The matrix:/n");
for(i=0; i<3; i++)
{for(j=0; j<4; j++)printf("%3d", w[i][j]);
printf("/n");
}
fun(w, a,
printf("The A array:/n");
for(i=0; i<n; i++)printf("%3d", a[i]); printf("/n/n");
NONO();
}
void NONO()
{/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/
FILE *rf, *wf; int i, j, k;
int w[10][10], a[100], n=0, mm, nn;
rf=fopen("in.dat", "r");
wf=fopen("out.dat", "w");
for(k=0; k<5; k++){
fscanf(rf, "%d %d:,
for(i=0; i<mm; i++)
for(j=0; j<nn; j++)fscanf(rf, "%d",
fun(w, a,
for(i=0; i<n; i++)fprintf(wf, "%3d", a[i]); fprintf(wf, "/n");
}
问答题请编写函数fun(),其功能是:将s所指字符串中除了下标为奇数、同时ASCII值为偶数的字符外,其余的全部删除,串中剩余字符所形成的一个新串放在t所指的数组中。 例如,若s所指字符串中的内容为edB2A4Dsdg,其中字符A的ASCII码值为奇数,因此应当删除;其中字符B的ASCII码值为偶数,但在数组中的下标为偶数,因此也应当删除:而字符2的ASCII码值为偶数,所在数组中的下标为奇数,因此不应当删除,其他依此类推。最后t所指的数组中的内容应是d24。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include <conio.h> #include <stdio.h> #include<string, h> void fun(char*s, char t[]) main() char s[100] ,t[100]; clrscr(); printf("/nPlease enter string S: "); scanf("%s",s); fun(s,t); printf("/nThe result is: %s/n",t);
问答题给定程序MODI1.C中函数fun的功能是:从s所指字符串中,找出与t所指字符串相同的子串的个数作为函数值返回。
例如,当s所指字符串中的内容为:"abcdabfab",t所指字符串的内容为:
"ab",则函数返回整数3。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main 函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
int fun (char *s, char *t)
{
int n; char *p , *r;
n = 0;
while ( *s )
{ p = s; r = t;
while ( *r )
if ( *r == *p ) {
/************found************/
r++; p++
}
else break;
/************found************/
if ( r == '/0' )
n++;
s++;
}
return n;
}
main()
{
char s[100], t[100]; int m;
printf("/nPlease enter string S:"); scanf("%s", s);
printf("/nPlease enter substring t:"); scanf("%s", t);
m = fun( s, t);
printf("/nThe result is: m = %d/n", m);
}
问答题给定程序中,函数fun的功能是:将a所指3×5矩阵中第k列的元素左移到第0列,第k列以后的每列元素行依次左移,原来左边的各列依次绕到右边。
例如,有下列矩阵:
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
若k为2,程序执行结果为
3 4 5 1 2
3 4 5 1 2
3 4 5 1 2
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:部分源程序在文件BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#define M 3
#define N 5
void fun(int(* a)[N],int k)
{int i,j,P,temp;
/*********found*********/
for(p=1;P<=
【1】
;P++)
for(i=0;i<M;i++)
{temp=a[i][0];
/*********found*********/
for(j=0;j<
【2】
;j++)
a[i][j]=a[i][j+1];
/*********found*********/
a[i][N一1]=
【3】
;
}
}
main()
{int x[M][N]={{1,2,3,4,5},{1,2,3,4,5},{1,2,3,4,5}},i,j;
printf("The array before moving:\n\n");
for(i=0;i<M;i++)
{ for(j=0;j<N;j++)
printf("%3 d",x[i][j]);
printf("\n");
}
fun(x,2);
printf("The array after moving:\n\n");
for(i=0;i<M;i++)
{ for(j=0;j<N;j++)
printf("%3d',x[i][j]);
printf("\n");
}
}
问答题请编写一个函数fun(),它的功能是将一个数字字符串转换为一个整数(不得调用C语言提供的将字符串转为整数的函数)。 例如,若输入字符串“-1234”,则函数把它转换为整数值 -1234。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include <stdio.h> #include <string.h> long fun(char *p) main ( ) char s[6]; long n; printf("Enter a string:/n"); gets(s); n=fun(s); printf("%ld/n",n);
问答题
给定程序MODI1.C中函数fun的功能是:首先将大写字母转换为对应小写字母;若小写字母为a~u,则将其转换为其后的第5个字母;若小写字母为v~z,使其值减21。转换后的小写字母作为函数值返回。例如,若形参是字母A,则转换为小写字母f:若形参是字母w,则转换为小写字母b。
请改正函数fun中指定部位的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
#include<stdio.h>
#include<ctype.h>
char fun(char c)
{ if(c>="A"
if(c>="a"
else if(c>="v"
return c;
}
main()
{char c1, c2;
printf("/nEnter a letter(A-Z):"); c1=getchar();
if(iaupper(c1))
{ c2=fun(c1);
printf("/n/nThe letter"%c" change to"%c"/n", c1, c2);
}
else printf("/nEnter (A-Z)!/n");
}
问答题给定程序MODI1.C中函数fun的功能是:应用递归算法求形参a的平方根。求平方根的迭代公式如下:例如,a为2时,平方根值为:1.414214。请改正程序中的错误,使它能得出正确结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。#include<stdio.h>#include<math.h>/**********found**********/doublefun(doublea,dounlex0){doublex1,y;x1=(x0+a/x0)/2.0;/**********found**********/if(fabs(x1-xo)>0.00001)y=fun(a,x1);elsey=x1;returny;}main(){doublex;printf("Enterx:");scanf("%lf",printf("Thesquarerootof%lfis%lf/n",x,fun(x,1.0));}
问答题请编写一个函数,用来删除字符串中的所有空格。 例如:输入asd af aa z67,则输出为asdafaz67。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include<stdio.h> #include<ctype.h> #include<conio.h> int fun(char*str) main() char str[81]; int n; clrscr(); printf("Input a string:"); gets(str); puts(str); fun(str); printf("*** Str: %s/n",str);
问答题假定输入的字符串中只包含字母和*号。请编写函数proc(),它的功能是:使字符串中前部的*号不得多于m个;若多于m个,则删除多余的*号;若少于或等于m个,则什么也不做,字符串中间和尾部的*号不删除。 例如,字符串中的内容为****A*BC*DEF*G*******,若m的值为2,删除后,字符串中的内容则应当是**A*BC*DEF*G*******;若m的值为4,则字符串中的内容仍为****A*BC*DEF*G*******。n的值在主函数中输入。在编写函数时,不得使用C语言提供的字符串函数。 注意:部分源程序已给出。 请勿改动主函数main和其他函数中的任何内容,仅在函数proc的花括号中填入所编写的若干语句。 试题程序: #include<stdio.h> #include<conio.h> void proc(char*a,int n) void main() char str[81];int m; printf("Enter a string:/n");gets(str); printf("Enter m:");scanf("%d",&m); proc(str,m); printf("The string after deleted:/n"); puts(str);
问答题给定程序中,函数fun的功能是将参数给定的字符串、整数、浮点数写到文本文件中,再用字符串方式从此文本文件中逐个读入,并调用库函数atoi和atof将字符串转换成相应的整数、浮点数,然后将其显示在屏幕上。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在
下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include <stdio.h>
#include <stdlib.h>
void fun(char *s,int a,double f)
{
/**********found**********/
______ fp;
char str[100],str1[100],str2[100];
int a1;double f1;
fp=fopen("file1.txt","w");
fprintf(fp,"%s %d %f/n",s,a,f);
/**********found**********/
______;
fp=fopen("file1.txt","r");
/**********found***********/
fscanf(______,"%s%s%s",str,str1,str2);
fclose(fp);
a1=atoi(str1);
f1=atof(str2);
printf("/nThe result:/n/n%s %d %f/n",str,a1,f1);
}
main()
{ char a[10]="Hello!";int b=12345;
double c=98.76;
fun(a,b,c);
}
问答题下列给定程序中,函数fun的功能是:将N×N矩阵中元素的值按列向右移动1个位置,右边被移出矩阵的元素绕回左边第1列。
例如,N=3,有下列矩阵
1 2 3
4 5 6
7 8 9
计算结果为:
3 1 2
6 4 5
9 7 8
请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include < stdio.h >
#define N 4
void fun(int(*t)[N])
{
int i,j,x;
for(i=o;i <
【1】
;i++)
{
X=t[i]
【2】
;
for(J=N—1;j >0;j一一)
t[i][j]=t[i][j一1];
t[i][
【3】
]=x;
}
}
main()
{
int i,j,t[][N]={21,12,13,24,25 , 16 , 47,38 , 29.11 , 32, 54 , 42 , 21 , 33,10};
printf("The orriginal array:/n");
for(i=0;i < N;i++)
{
for(j=0;j < N;j++)
printf("%2d",t[i][j]);
printf("/n");
}
fun(t);
printf("/nThe result is:/n");
for(i=0;i < N;i++)
{
for(j=0;j < N ; j++)
printf("%2d",t[i][j]);
printf("/n");
}
}
问答题下列给定程序中,函数fun的功能是:求ss所指字符串数组中长度最短的字符串所在的行
下标,作为函数值返回,并把其串长放在形参n所指的变量中。ss所指字符串数组中共有M个字符串,且串长小于N。
请在程序的下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。
注意:部分源程序在文件BLANK1.C中。不得增行或删行,也不得更改程序的结构。
#include
#include #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++) {len=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 3={''shanghai'',''guangzhou'',''beijng'',''tianjin'',''chongqing''}; int n,k,i; printf(''\nThe original strings are:\n''); for(i=0;i<M;i++)puts(ss[il); k=fun(ss,&n); printf(''\nThe length of shortest string is:%d\n'',n); printf(''LaThe shortest string is:%s\n'',ss[k]); }
问答题给定程序中,函数fun的功能是:
把形参s所指字符串中最右边的n个字符复制到形参t所指字符数组中,形成一个新串。若s所指字符串的长度小于n,则将整个字符串复制到形参t所指字符数组中。
例如,形参s所指的字符串为:abodefgh,n的值为5,程序执行后t所指字符数组中的字符串应为:
defgh。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:部分源程序在文件BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include < stdio.h >
#include < string.h >
#define N 80
void fun(char,* s,int n,char*t)
{int fen,i,j=0;
len=str1en(s);
/*********found*********/
if(n >=1en)strcpy(
【1】
);
else{
/*********found*********/
for(i=1en一n;i < =1en一1;i++)
t[j++]=
【2】
;
/*********found*********/
t[j]=
【3】
;
}
}
main()
{char s[N],t[N];int n;
printf("Enter a string:");
gets(s);
printf("Enter n:");
scanf("%d",&n);
fun(s,n,t);
printf("The string t:");
puts(t);
}
问答题请编写函数fun,该函数的功能是:统计备年龄段的人数。N个年龄通过调用随机函数获得,并放入主函数的age数组中。要求函数把0~9岁年龄段的人数放在d[0]中,把10~19岁年龄段的人数放在d[1]中,把20~29岁年龄段的人数放在d[2]中,依次类推,把100岁(含100岁)以上年龄的人数都放在d[10]中。结果在主函数中输出。
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#define N 50
#define M 11
void fun(int *a, int *b)
{
}
double rnd()
{
static t=29, c=217, m=1024, r=0;
r=(r*t+c)%m;
return((double)r/m);
}
void main()
{
int age[N], i, d[M];
for(i=0; i<N; i++)
age[i]=(int)(115*rnd());
/*产生一个随机的年龄数组*/
printf("The original data:/n");
for(i=0; i<N; i++)
printf((i+1)%10==0?"%4d/n":"%4d", age[i]);
/*每行输出10个数*/
printf("/n/n");
fun(age, d);
for(i=0; i<10; i++)
printf("%4d-%4d:%4d/n", i*10, i*10+9, d[i]);
printf("Over 100:%4d/n", d[10]);
}
问答题改错题
下列给定程序中,函数fun()的功能是:读入一个字符串(长度
#include
/**********************found***********************/
int fun(char t[ ])
{
char c;
int i,j;
for(i=0;i
问答题请编写函数fun,其功能是:计算并输出当x<0.97时下列多项式的值,直到|Sn-Sn-1|<0.000001为止。例如,在主函数中从键盘给x输入0.21后,输出为:s=1.100000。注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。1#include<stdio.h>2#include<math.h>3doublefun(doublex)4{5}6NONO()7{/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/8FILE*rf,*wf;inti;doubles,x;9rf=fopen(''in.dat'',''r''”);10wf=fopen(''out.dat'',''w'');11for(i=0;i<10;i++){12fscanf(rf,''%1f'',&x);13s=fun(x);14fprintf(wf,''%1f\n'',s);15}16fclose(rf);fclose(wf);17}18main()19{doublex,s;20printf(''Input:x:'');scanf(''%1f'',&x);21s=fun(x);22printf(''s=%f\n'',s);23NONO();}
