问答题学生的记录由学号和成绩组成。N名学生的数据已放入主函数中的结构体数组s中,请编写函数fun,其功能是:把高于等于平均分的学生数据放在b所指的数组中,高于等于平均分的学生人数通过形参n传回,平均分通过函数值返回。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#define N 12
typedef struct
{
char num[10];
double s;
}STREC;
double fun(STREC *a, STREC *b, int *n)
{
}
void main()
{
STREC s[N]={{"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[N];
int i, n;
double ave;
ave=fun(s, h,
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[j].s);
printf("/n");
}
问答题给定程序中,函数fun的功能是:
利用指针数组对形参ss所指字符串数组中的字符串按由长到短的顺序排序,并输出排序结果。ss所指字符串数组中共有N个字符串,且串长小于M。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:部分源程序在文件BIANK1.C中。
不得增行或删行,也不得更改程序的结构!
试题程序:
#1r1clucle < stotio.h >
#include < string.h >
#define N 5
#define M 8
void fun(char(*ss)[M])
{char*ps[N],* tp;int i,j,k;
for(i=0;i < N;i++)
ps[i]=ss[i];
for(i=0 ; i < N—1;i++){
/*********found*********/
k=
【1】
;
for(j=i+l;j < N;j++)
/*********found*********/
if(str1en(ps[k]) < str1en
(
【2】
)k=j;
/*********found*********/
tp=ps[i];ps[i]=ps[k];
ps[k]=
【3】
;
}
printf f"/nThe string after
sorting by length:/n/n");
for(i=0;i < N;i++)puts(ps[i]);
}
main()
{ char ch[N] [M] = { "red","green",
"blue ", "yellow", "black" } ;
int i;
printf ( " /nThe original string
puts (ch[i] ) ; printf ("/n") ;
fun (ch) ;
}
问答题编写函数fun,它的功能是:求小于形参n同时能被3与7整除的所有自然数之和的平方根,并作为函数值返回。
例如,若n为1000时,程序输出应为:s=153.909064。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include<math.h>
#include<stdio.h>
double fun(int n)
{
}
main()/*主函数*/
{
printf("s=%f/n",fun(1000));
}
问答题下列给定程序中,函数fun()的功能是:从s所指字符串中,找出t所指字符串的个数作为函数值返回。例如,当s所指字符串中的内容为abcdabfab,t所指字符串的内容为ab,则函数返回整数3。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构. 试题程序: #include <conio.h> #include <stdio.h> #include <string.h> int fun (char *s, char *t) int n; char *p, *r; n=0; while(*s) p=s; r=t; while (*r) /**************found**************/ if(*r==*p) r++; p++ else break; /*************found**************/ if(r=='/0') n++; s++; return n; main() char s[100], t[100]; int m; clrscr(); 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,该函数的功能是:将s所指字符串中ASCII码值为偶数的字符删除,串中剩余字符形成一个新串放在t所指的数组中。
例如,若s所指字符串中的内容为“ABCDEFG12345”,其中字符B的ASCII码值为偶数,字符2的ASCII码值为偶数,都应当删除,其他依次类推。最后t所指的数组中的内容应是“ACEG135”。
注意
:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>
void fun(char *s,char t[])
{
}
void main()
{
char s[100],t[100];
system{"CLS");
printf("/nPlease enter string S:");
scanf("%s",s);
fun(s,t);
printf("/nThe result is:%s/n",t);
}
问答题请编写函数fun:在形参指针所指的4个整数中找出最大值和最小值,最大的放在a中,最小的放在d中。
注意:部分源程序存在PROG1. C中,请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
#include <stdio. h>
void NONO( );
void fun(int *a, int *b, int*c, int *d)
{
}
main( )
{int a, b, c, d;
printf("请输入4个整数: ");
scanf("%d%d%d%d",
printf("原始顺序: %d, %d, %d, %d/n", a, b, c, d);
fun(
printf("处理后: %d, %d, %d, %d/n", a, b, c, d);
NONO( );
}
void NONO( )
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/
FTLE *fp, *wf;
int i, a, b, c, d;
fp=fopen
("C://WEXAM//24990001//in. dat", "r");
wf=fopen
("C://WEXAM//24990001//out. dat", "w");
for(i=0; i<5; i++)
{
fscanf(fp, "%d%d%d%d",
fun(
fprintf(wf, "a=%d, d=%d/n", a, d);
}
fclose(fp);
fclose(wf);
}
问答题函数fun的功能是:将s所指字符串中除下标为偶数同时ASCII码值也为偶数的字符外,其余的全部删除;字符串中剩余字符所形成的新串放在t所指的数组中。
例如,若s所指字符串中的内容为
“ABCDEFGl23456”,其中字符A的ASCII码值为奇数,因此应当删除;字符B的ASCII码值为偶数,但在数组中的下标为奇数,因此也应当删除;字符2的ASCII码值为偶数,在数组中的下标也为偶数,因此不应当删除,其他依次类推。最后t所指的数组中的内容应是“246”。
注意
:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
void fun(char*s, char t[])
{
}
void main()
{
char s[100],t[100];
system("CLS");
printf("/nPlease enter string S:");
scanf("%s",s);
fun(s,t);
printf("/nThe result is:%s/n",t);
}
问答题函数fun的功能是:把形参a所指数组中的偶数按原顺序依次存放到a[0],a[1]、a[2]、……中,把奇数从数组中删除,偶数个数通过函数值返回。例如:
若a所指数组中的数据最初排列为:9、1、4、2、3、6、
5、8、7,删除奇数后a所指数组中的数据为:4、2、6、8,返回值为4。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include
#define N 9
int fun (int a[], int n)
{ int i,j;
j = 0;
for(i=0;i
问答题给定程序MODI1.C中函数fun的功能是:根据整型形参m,计算如下公式的值。
1 1 1 1
y = ------- + --------- + --------- + …… + -------
100*100 200*200 300*300 m*m
例如,若m = 2000,则应输出: 0.000160。
请改正程序中的语法错误,使它能计算出正确的结果。
注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
/************found************/
fun ( int m )
{ double y = 0, d ;
int i ;
/************found************/
for( i = 100, i <= m, i += 100 )
{ d = (double)i * (double)i ;
y += 1.0 / d ;
}
return( y ) ;
}
main( )
{ int n = 2000 ;
printf( "/nThe result is %lf/n", fun ( n ) ) ;
}
问答题编写函数fun(),其功能是:求ss所指字符串中指定字符的个数,并返回此值。
例如,若输入字符串“123412132”,输入字符为“1”,则输出3。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数fun()的花括号中填入你编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#define M 81
int fun(char*ss, char c)
{
}
void main()
{
char a[M], ch;
system("CLS");
printf("/n Please enter a string:");
gets(a);
printf("/nPlease enter a char:");
ch=getchar();
printf("/nThe number of the char is:%d/n", fun(a, ch));
}
问答题请编写函数fun,其功能是:计算并输出给定数组(长度为9)中每相邻两个元素的平均值的平方根之和。
例如,若给定数组中的9个元素依次为1210、3410、410、230、340、450、180、310、110,则输出应为S=35.951014。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#include<math.h>
double fun(double x[9])
{
}
main()
{
double s,a[9]={12.0,34.0,4.0,23.0,34.0,45.0,18.0,3.0,11.0};
int i;
printf("/nThe original data is:/n");
for(i=0;i<9;i++)
printf("%6.1f",a[i]);
printf("/n/n");
s=fun(a);
printf("S=%f/n/n",s);
}
问答题请编写函数fun,其功能是:判断t所指字符串中的字母是否由连续递增字母序列组成(字符串长度大于等于2)。例如字符串:uvwxyz满足要求;而字符串:uvxwyz不满足要求。注意:部分源程序存放在PROGl.C中,请勿改动主函数main和其他函数中的任何内容,仅在函数fun指定的部位填入所编写的若干语句。试题程序:#include<stdio.h>#include<string.h>void NONO();int fun(char*t){}main(){char s[26];printf("请输入一个字母组成的字符串:");gets(s);if(fun(s))printf("%s是由连续字母组成的字符串.\n",s);else pfinff("%s不是由连续字母组成的字符串!\n",s);NONO();}void NONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE*fp,*wf;int i;char s[26],*p;fp=fopen("in.dat","r");wf=fopen("out.dat","w");for(i=0;i<10;i++){fgets(s,26,fp);p=strchr(s,'\n');if(p)*p=0;if(fun(s))fprintf(wf,"%s\n",s+2);else finff(wf,"%s\n",strrev(s));}fclose(fp);fclose(wf);}
问答题请编写函数fun,其功能是将两个两位数的正整数a、b合并形成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数个位和十位上,b数的十位和个位数依次放在c数的百位和千位上。
例如,当a=16,b=35,调用该函数后,c=5361。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
void fun(int a,int b/long*c)
{
}
main()
{
int a,b;
long c;
clrscr();
printf("Input a,b;");
scanf("%d%d",&a,&b);
fun(a,b,&c);
printf("The result is:%ld/n",c);
}
问答题下列给定程序中,函数fun的功能是:求s的值。例如,当k为10时,函数的值应为1.533852。请改正程序中的错误,使它能得出正确的结果。注意:部分源程序在文件MODI1.C中,不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<stdlib.h>#include<conio.h>#include<stdio.h>#include<math.h>/*********found*********/fun(intk){intn;floats,w,p,q;n=1;s=1.0;while(n<=k){w=2.0*n;P=w一1.0;q=w+1.0;S=s*w*w/p/q;n++;}/*********found*********/returns}voidmain(){system("CLS"),printf("%f\n",fun(10));}
问答题给定程序MODI1.C中,函数fun的功能是:判断输入的任何一个正整数n,是否等于某个连续正整数序列之和。若是,则输出所有可能的序列,否则输出“不能分解”。例如:当输入100时,输出:100 =9+10+11+12+13+14+15+16100 =18+19+20+21+22请改正函数fun中指定部位的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。试题程序:#include < stdio.h >void fun ( int n ){ int j, b, c, m, f1ag=0;for(b=1;b < =n/2;b++){/*********found*********/n=m;c=b;while(m!=0&&m >=c){/*********found*********/m=m—c;c++}/*********found*********/if(m!=0){printf("%d=",n);for(j=b;j < c一1;j++)printf("%d+",j);printf("%d/n",j);f1ag=1;}}if(f1ag=0)printf("不能分解/n");}main(){ int n;printi("请输入一个整数:");scanf("%d",&n);fun(n);}
问答题编写函数,调用随机函数产生0到19之间的随机数,在数组中存入15个互不重复的整数。要求在主函数中进行输出结果。若已定义x为int类型,调用随机函数步骤如下:
#include<stdlib.h>
x=rand()%20; /*产生0到19的随机数*/
问答题下列程序定义了N×N的二维数组,并在主函数中赋值。请编写函数fun,函数的功能是:求出数组周边元素的平均值并作为函数值返回给主函数中的s。例如,若a数组中的值为: 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 则返回主程序后s的值应为3. 375。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数rruun和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序:#include < stdio.h >#include < conio .h >#include < stdlib .h >#define N 5double fun (int w[] [N]){}void main (){ FILE *wf; int a[N][N] = {0,1,2 f 7,9,1,9, 7 , 4 , 5,2 , 3 , 8 , 3 , 1 , 4 , 5 , 6 , 8 , 2 , 5,9, 1,4,1}; int i, j; double s; system ( "CLS") ; printf (" *** The array *** /n ") ; printf "'/n ") ; s = fun (a) ; printf (" *** THE RESULT *** /n ") ; printf("The sum is : oo lf/n ",s);/******************/ wf = fopen ("out.dat", "w") ; fprintf (wf, "% lf",s) ; fclose (wf) ;/******************/}
问答题假定输入的字符串中只包含字母和*号。请编写函数proc(),它的功能是:将字符串尾部的*号全部删除,前面和中间的*号不删除。
例如,若字符串中的内容为****a*bc*def*g****,删除后,字符串中的内容则应当是****a*bc*def*g。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数proc的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#include<conio.h>
void proc(char *str)
{
}
void main()
{
char s[81];
printf("Enter a string:/n");
gets(s);
proc(s);
printf("The string after deleted:/n");
puts(s);
}
问答题下列给定程序中,函数tim的功能是:先将字符串s中的字符按正序存放到字符串t中,然后把s中的字符按逆序连接到字符串t的后面。例如,当s中的字符串为“ABCDE”时,则t中的字符串应为“ABCDEEDCBA”。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<stdlib.h>#include<conio.h>#include<stdio.h>#include<string.h>void fun(char*s,char*t){ int i,s1; s1=strlen(s);/*********found*********/ for(i=0;i<=s1;i++) t[i]=S[i]; for(i=0;i<s1;i++) t[s1+i]=S[i];/*********found*********/ t[s1]='\0'; } void main() { char s[100],t[100]; system("CLS“); printf(”\nPlease enter string s:"); scanf("%S",S); fun(S,t); printf {"The result is:%s\n",t);}
问答题给定程序MODI1.C中函数fun的功能是:判断一个整数是否是素数,若是返回1,否则返回0。 在main()函数中,若fun返回1输出YES,若fun返回0输出NO!。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数。不得增行或删行,也不得更改程序的结构! #include<stdio.h> int fun(int m) { int k=2; while(k<=m&&(m%k)) /************found************/ k++ /************found************/ if(m=k)return 1; else return 0; } main() { int n; printf("\nPlease enter n:");scanf("%d“,&n); if(fun(n))printf("YES\n"); else printf("NO!\n");}
