学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构件数组s中,请编写函数fun(),它的功能是:把分数最高的学生数据放在h所指的数组中。注意:分数高的学生可能不只一个,函数返回分数最高学生的人数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
define N 16
typedef struct
{ char num[10];
int s;
}STREC;
int fun(STREC *a,STREC *b)
{
}
main ()
{
STREC s [N] = { { "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 } };
STREC h[N];
int i, n;
FILE *out;
n=fun(s,h);
printf("The %d highest score :\n",n);
for (i=0; i<n; i++)
printf("%s %4d\n ",h[i].num, h[i].s);
/*输出最高分学生的学号和成绩* /
printf("\n");
ut=fopen("out45.dat", "w");
fprintf(out, "%d\n",n);
for(i=0; i<n; i++)
fprintf(out, "%4d\n ",h[i].s);
fclose(out);
}
第1题
回这些数的个数。
例如,若传给m的值为50,则程序输出:
7 11 14 21 X 28 33 35 42 44 49
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio.h>
include<stdio.h>
define M 100
void fun(int m, int *a, int *n)
{
}
main()
{
int aa[M],n,k;
clrscr();
fun(50,aa,&n);
for(k=0;k<n; k++)
if((k+1)%20==0) /*每行输出20个数*/
{printf("%4d",aa[k]);
printf("\n");
}
else
printf("%4d",aa[k]);
printf("\n");
}
第2题
下列给定程序中函数fun()的功能是计算1/n!的值。
例如:给n输入5,则输出0.0083330
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <conio.h>
/******+****found*************/
int fun(int n)
{double result=1.0;
if(n==0)
return 1.0;
while(n>1 && n<170)
/**********found************/
result *=n++;
result=1/result;
return result;
}
main()
{
int n;
printf("Input N:");
scanf("%d",&n);
printf("\n1/%d!=%If\n",n,fun(n));
}
第3题
请补充main函数,该函数的功能是求方程ax2+bx+c=0的根(方程的系数a,b,c从键盘输入)。
例如, 当a=1,b=2,c=1时, 方程的两个根分别是:
x1=-1.00,x2=-1.00。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
include <conio.h>
include <math.h>
main()
{
float a,b,c,disc,x1,x2,p,q;
scanf("%f,%f,%f",&a,&b,&c);
disc=b*b-4*a*c;
clrscr();
printf("****** the result ****+*+\n");
if(disc>=0)
{
x1=【 】;
x2=(-b-sqrt(disc))/(2*a);
printf("x1=%6.2f,x2=%6.2f\n",x1,x2);
}
else
{
p=【 】;
q=【 】;
printf("x1=%6.2f+%6.2f i\n",p,q);
printf("x2=%6.2f-%6.2f i\n",p,q);
}
}
第4题
符都删除,串中剩余字符所形成的一个新串放在t所指的数组中。例如,若str所指字符串中的内容为ABCDEFGl2345,其中字符B的ASCIl码值为偶数,所在元素的下标为奇数,因此必须删除;而字符A的ASCIl码值为奇数,所在数组中的下标为偶数,因此不应当删除。依此类推,最后t所指的数组中的内容应是ACEG。 注意:部分源程序给出如下。 请勿改动main函数和其他函数中的任何内容,仅在函数proc的花括号中填人所写的若干语句。 试题程序: include<stdlib.h> include<conio.h> include<stdio.h> include<string.h> void proc(char*str,char t[]) { } void main { char str[100],t[100]; system("CLS"); printf("\nPlease enter string str:"); scanf("%S",str); proc(str,t); printf("\nThe result iS:%s\n",t);
第5题
他函数中的任何内容,仅在函数proc的横线上填入所编写的若干表达式或语句。 试题程序: include<stdio.h> long proc(int n) { if( 【1】 ) return(n*proc( 【2】 ); else if(【3】) return l; } void main { int k=7: printf("%d!=%ld\n",k,proc(k)); }
第6题
+(-1)(n+1)/(nn) 例如,n中的值为l0,则应输出0.817962。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: include<stdlib.h> include<conio.h> include<stdiO h> double proc(int n) { double y=1.0; //****found**** int J=1; . int i; for(i=2;i<=n;i++) { j=-l*j;//****found**** y+=1/(i*i); } return(y); } void main { int n=10: system("CLS"): printf("\nThe result is%1f\n",proc(n)); }
第7题
数组中数据的个数存放在形参n所指的存储单元中。 例如,若二维数组中的数据为 13 23 33 43 14 24 34 44 15 25 35 45 则一维数组中的内容应该是13 23 33 43 14 24 34 44 15 25 35 45。 注意:部分源程序给出如下。 请勿改动main函数和其他函数中的任何内容,仅在函数proc的花括号中填入所编写的若干语句。 试题程序: include<stdio.h> void proc(int(*s)[103,int*b,int*n,int rain.int nn) {
} void main { int arr[10][10]={{33,33,33,33),{44,44,44,44}, {55,55,55,55}),i,j; int a[l00]={o),n=o; printf("The matrix:\n"); for(i=0;i<3;i++) { for(j=0;j<4;j++) printf("%3d",arr[i][j]): printf("\n"); } proc(arr,a,&n,3,4): printf("The A array:\n"); for(i=0;i<n;i++) printf("%3d",a[i]): printf("\n\n"); }
第8题
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); ut=fopen("outfile.dat","w"); fprintf(out,"%s".a); fclose(out); }
第9题
中:成绩为60~69的人数存到b[0]中,成绩为70~79的人数存到b[1]中,成绩为80~89的人数存到b[2]中,成绩为90~99的人数存到b[3]中,成绩为100的人数存到b[4]中,成绩为60分以下的人数存到b[5]中。
例如,当a数组中的数据是:93、85、77、68、59、43、94、75、98,调用该函数后,b数组中存放的数据应是:1、2、1、3、0、2。
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在横线上填入所编写的若于表达式或语句。
试题程序:
includedstdi0.h>
void fun(int a[],int b[],int n)
{
int i;
for(i=0;i<6;I++)
b[i]=0;
for(i=0:i<【1】 ;i++)
if(a[i]<60)
b[5]++;
【2】
b[(a[i]一60)/10]++;
}
void main
{
int i,a[100]={93,85,77,68,59,43,94,75,98),b[6];
fun(【3】 ,9);
printf("the result is:");
for(i=0;i<6;i++)
printf("%d",b[i]);
printf("\n,");
}
第10题
所有整数,把这些整数放在s所指的数组中,个数作为函数值 返回。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: include<stdio.h> define M 1000 int proc(int*S.int n) { int i,j,k,a,b,c; j=0; for(i=100;i<n;i++) { //****found**** k=n: a=k%10; k/=10; b=k%10; c=k/10; if(a==b+c) //****found**** s[j]=i: } return j; } void main { int a[M],m,num=0,i; do { printf("\nEnter m(<=1000):"); scanf("%d",&m); } while(m>1000); num=proc(a,m); printf("\n\nThe result:\n"); for(i=0;i<num;i++) printf("%5d",a[i]); printf("\n\n"); }
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!