问答题程序通过定义学生结构体变量,存储了学生的学号、姓名和3门课的成绩。函数fun的功能是将形参a中的数据进行修改,把修改后的数据作为函数值返回主函数进行输出。
例如:传给形参a的数据中,学号、姓名、和三门课的成绩依次是:10001、"ZhangSan"、95、80、88,修改后的数据应为:10002、"LiSi"、96、81、89。
请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
struct student {
long sno;
char name[10];
float score[3];
};
/**********found**********/
__1__ fun(struct student a)
{ int i;
a.sno = 10002;
/**********found**********/
strcpy(__2__, "LiSi");
/**********found**********/
for (i=0; i<3; i++) __3__+= 1;
return a;
}
main()
{ struct student s={10001,"ZhangSan", 95, 80, 88}, t;
int i;
printf("/n/nThe original data :/n");
printf("/nNo: %ld Name: %s/nScores: ",s.sno, s.name);
for (i=0; i<3; i++) printf("%6.2f ", s.score[i]);
printf("/n");
t = fun(s);
printf("/nThe data after modified :/n");
printf("/nNo: %ld Name: %s/nScores: ",t.sno, t.name);
for (i=0; i<3; i++) printf("%6.2f ", t.score[i]);
printf("/n");
}
问答题编写函数fun,其功能是:求ss所指字符串中指定字符的个数,并返回此值。 注意:部分源程序给出如下。 请勿改动主函数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 (" / nPlease enter string: "); gets (a); printf ("/nPlease enter a char:"); ch=getehar (); printf ("/nThe number of the char is:% d/n", fun(a, ch));
问答题规定输入的字符串中只包含字母和*号。编写函数fun,其功能是:除了字符串前导和尾部的*号外,将串中其他的*号全部删除。形参h已指向字符串中第—个字母,形参P指向字符串中最后一个字母。在编写函数时,不得使用C语言提供的字符串函数。 例如,若字符串中的内容为“****A*BC*DEF*G********”,删除后,字符串中的内容应当是 “****ABCDEFG********”。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序:#include < stdio.h >#include < conio.h >#include < string.h >void fun(char*a,char*h,char*p){}main(){ char s[81],*t,*f; printf("Enter a string:/n"); gets(s); t=f=s; while(*t) t++; t一一; while(*t=='*') t一一; while(*f=='*') f++; fun(s,f,t); printf("The string afterdeleted:/n"); puts(s);}
问答题下列给定程序中,函数fun的功能是:读入一个字符串(长度< 20),将该字符串中的所有字符按ASCII码值升序排序后输出。例如,若输入“edcba”,则应输出“abcde”。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,
也不得更改程序的结构!
试题程序:
#include<string.h>
#include<stdio.h>
void fun(char t[])
{
char c;
int i,j;
/********found********/
for(i=strlen(t)-i;i--)
for(j=0;j<i;j++)
/********found********/
if(t[j]<t[j+1])
{
c=t[j];
t[j]=t[j+1];
t[j+1]=c;
}
}
main()
{
char s[81];
printf("/n Please enter a character string:");
gets(s);
printf("/n/nBefore sorting:/n%s",s);
fun(s);
printf("/nAfter sorting decendingly:/n%s",s);
}
问答题请编写函数fun,其功能是:统计s所指字符串中的数字字符个数,并作为函数值返回。 例如,s所指字符串中的内容是:2det35adh253kjsdf 7/kj8655x, 函数fun返回值为:11 注意:部分源程序在文件PROG1.C文件中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序:#include < stdio.h >void NONO();int fun(char*s){}main(){char*s="2clef35adh25 3kjsdf7/kj8655x"; printf("%s/n",s); printf("%d/n",fun(s)); NONO();}void NONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/ FILE*fp,* wf; int i; char s[256]; fp=fopen("in.clat","r"); wf=fopen("out.dat","w"); for(i=0;i < 10;i++){ fgets(s,2 55,fp); fprintf(wf,"%d/n",fun(s)); } fclose(fp); fclose(wf);}
问答题给定程序中,函数fun的功能是:判定形参a所指的N×N(规定N为奇数)的矩阵是否是"幻方",若是,函数返回值为1; 不是,函数返回值为0。"幻方"的判定条件是:矩阵每行、每列、主对角线及反对角线上元素之和都相等。
例如,以下3×3的矩阵就是一个"幻方":
4 9 2
3 5 7
8 1 6
请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#define N 3
int fun(int (*a)[N])
{ int i,j,m1,m2,row,colum;
m1=m2=0;
for(i=0; i
{ j=N-i-1; m1+=a[i][i]; m2+=a[i][j]; }
if(m1!=m2) return 0;
for(i=0; i
/**********found**********/
row=colum= __1__;
for(j=0; j
{ row+=a[i][j]; colum+=a[j][i]; }
/**********found**********/
if( (row!=colum) __2__ (row!=m1) ) return 0;
}
/**********found**********/
return __3__;
}
main()
{ int x[N][N],i,j;
printf("Enter number for array:/n");
for(i=0; i
for(j=0; j
printf("Array:/n");
for(i=0; i
{ for(j=0; jprintf("/n");
}
if(fun(x)) printf("The Array is a magic square./n");
else printf("The Array isn't a magic square./n");
}
问答题下列给定程序中,函数fun的功能是:将tt所指字符串中的小写字母全部改为对应的大写字母,其他字符不变。 例如,若输入“Ab,CD”,则输出“AB,CD”。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #lnclude<conio.h> #include<stdio.h> #include<string.h> char*fun(char tt[]) ( int i; for(i=O;tt[1];i++) /******found******/ if((tt[i]>='a')||(tt[i]<='z')) /******found********/ tt[i]+=32; return(tt); main() char tt[81]; printf("/nPlease enter a string:"); gets(tt); printf(/nThe result string is/n%s"fun(tt));
问答题给定程序中,函数fun的功能是:在形参ss所指字符串数组中查找与形参t所指字符串相同的串,找到后返回该串在字符串数组中的位置(下标值),未找到则返回-1。ss所指字符串数组中共有N个内容不同的字符串,且串长小于M。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构! #include<stdio.h> #include<string.h> #define N 5 #define M 8 int fun(char(*ss)[M],char*t) {int i; /**********found**********/ for(i=0;i<___________(1);i++) /*********found**********/ if(strcmp(ss[i],t)==0)return___________(2); return-1; } main() { char ch[N][M]={"if","while","switch","int","for"},t[M]; int n,i; printf("\nThe original string\n\n"); for(i=0;i<N;i++)puts(ch[i]);printf("\n"); printf("\nEnter a string for search:");gets(t); n=fun(ch,t); /*********found**********/ if(n==__________(3)printf("\nDon′t found!\n"); else printf("\nThe position is %d.\n",n); }
问答题给定程序中,函数fun的功能是:将形参n中,各位上为偶数的数取出,并按原来从高位到低位的顺序组成一个新的数,并作为函数值返回。 例如,从主函数输入一个整数:27638496,函数返回值为:26846。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 unsigned long fun(unsigned long n)3 { unsigned long x=0,s,i;int t;4 s=n;5 /**********found**********/6 i= __1__;7 /**********found**********/8 while(__2__)9 { t=s%10;10 if(t%2==0){11 /**********found**********/12 x=x+t*i;i=__3__;13 }14 s=s/10;15 }16 return x;17 }18 main()19 { unsigned long n=-1;20 while(n>99999999 || n<0)21 { printf(''Please input(0<n<100000000):'');scanf(''%1d'',&n);}22 printf(''\nThe result is:%1d\n'', fun(n));23 }
问答题给定程序中,函数fun的功能是:求出形参ss所指字符串数组中最长字符串的长度,将其余字符串右边用字符“*”补齐,使其与最长的字符串等长。ss所指字符串数组中共有M个字符串,且串长
#include
#define M 5
#define N 20
void fun (char (*ss)[N])
{ int i, j, n, len=0;
for(i=0; in)n=len;
}
for(i=0; i
问答题下列给定程序中,函数fun的功能是:从P所指字符串中找出ASCII码值最大的字符,将其放在第一个位置上,并将该字符前的原字符向后顺序移动。例如,调用fun函数之前给字符串输入“ABCDeFGH”,调用后字符串中的内容应为“eABCDFGH”。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<stdio.h>void fun(char*P){ char max,*q;int i=0; max=P[i]; while(p[i]!=0) { if(max<P[i]) {max=P[i];/*********found*********/ q=P+i } i++; }/*********found*********/ while(q<P) { *q=*(q一1);q--; } P[0]=max;}void main(){ char str[80]; printf("Enter a string:"); getS(str), printf("\nThe original string:"); puts(str); fun(str); printf("\nThe string after moving:"); puts(str);printf("\n\n");}
问答题请编写函数fun,其功能是:判断形参n中的正整数是几位数(输入数据的位数不超过4位),并将结果通过函数值返回。例如,若输入的数据为123,则输出结果为:输入的数字是3位。 注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序:#inelude<stdio.h>void NONO();int fun(int n){}main(){ int n,place; do { printf(“请输入—个4位以内的正整数:”); scanf(“%d”,&n); } while(n<0 ‖ n>9999); place=fun(n); printf(“输入的数字是%d位\n”,place); NONO();}void NONO()/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/{ FILE*fp,*wf; int i,n,place; fp=fopen(“in.dat”,“r”); wf=fopen(“out.dat”,“w”); for(i=0;i<10;i++) { fscanf(fp,“%d”,&n); place=fun(n); fprintf(wf,“%d\n”,place); } fclose(fp); fclose(wf);}
问答题请编写函数fun,该函数的功能是:求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。 例如,若二维数组中的值为: 1 3 5 7 9 2 9 9 9 4 6 9 9 9 8 1 3 5 7 0 则函数值为61。 注意:部分源程序在文件PROG1.C中。 请勿改主动函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序:#include < conio.h >#include < stdio .h >#include < stdlib.h >#define M 4#define N 5int fun ( int a [M] [N1) { }void main () { FILE *wf; int aa[M] [N] = {{1,3,5,7,9 },{2,9,9,9,4},{ 6,9,9,9,8},{1,3,5,7,0 }}; int i, j, y; system ("CLS ") ; printf ("The original data is for (1 =0; i < Mf i++) printf ("% 6d ",aa[i] [ j ]) ; printf ("/n ") ; } y = fun (aa) ; printf ("/nThe sun: % d/n "y) ; printf ("/n ") ;/*********found*********/ wf = fopen ("out.dat", "w") ; fprintf (wf, "% d", y) ; fclose (wf) ;/*********found*********/}
问答题下列给定程序中,函数fun的功能是:用选择法对数组中的n个元素进行升序排列。 请修改程序中的错误,使它能得出正确的结果。 注意:不得增行和删行,也不得更改程序的结构! 试题程序: #include<stdio.h> #define N 20 void fun(int a[],int n) { int i,j,t,p; for(j=0;j<n一1;j++) { /******found******/ p=j for(i=j;i<n;i++) if(a[i]<a[p]) /******found******/ p=j; t=a[p];a[p]=a[j];a[j]=t; } } main() { int a[N]={9,6,8,3,一1},i,m=5; printf("排序前的数据:"); for(i=0;i<m;i++) printf("%d",a[i]); printf("\n"); fun(a,m); printf("排序后的数据:"); for(i=0;i<m;i++) printf("%d",a[i]); printf("\n"); }
问答题函数fun的功能是:将两个两位数的正整数a、b合并形成一个整数放在c中。
合并的方式是:将a数的十位和个位数依次放在c数的个位和百位上,b数的十位和个位数依次放在c数的千位和十位上。
例如,当a=45,b=12时,调用该函数后,c=1524。
注意:部分源程序存在文件PROG1.C中。数据文件in.dat中的数据不得修改。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入要编写的若干语句。
#include<stdio.h>
void fun(int a,int b,long*c)
{
}
main()
{int a,b;long c;
void NONO();
printf("Input a,b:");
scanf("%d,%d",
fun(a,b,
printf("The result is:%1d/n",c);
NONO();
}
void NONO()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/
FILE*rf,*wf;
int i,a,b;long c;
rf=fopen("in.dat","r");
wf=fopen("out.dat","w");
for(i=0;i<10;i++){
fscanf(rf"%d,%d",
fun(a,b,
fprintf(wf,"a=%d,b=%d,e=%ld/n",a,b,c);
}
fclose(rf);
fclose(wf);
}
问答题规定输入的字符串中只包含字母和*号。编写函数fun(),其功能是:删除字符串中所有的*号。编写函数时,不得使用C语言提供的字符串函数。
例如,字符串中的内容为“****A*BC*DEF*G****”,删除后,字符串中的内容应当是“ABCDEFG”。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数fun()的花括号中填入你编写的若干语句。
试题程序:
#include<conio.h>
#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);
}
问答题下列给定程序中函数fun的功能是:将m(1≤m≤10)个字符串连接起来,组成一个新串,放入pt所指存储区中。例如:把三个串“abe”、“CD”、“EF”连接起来,结果是“abcCDEF”。请改正程序中的错误,使它能得出正确的结果。
注意:
不要改动main函数,不得增行或删行,也不得更改程序的结构!
[试题源程序]
#include<stdio.h>
#include<string.h>
void fun(char str[][10],int m,char*pt)
{
/**********found**********/
Int k,q,i;
for(k=0;k<m;k++)
{q=strlen(str[k]);
for(i=0;i<q;i++)
/**********found**********/
pt[i]=str[k,i];
pt+=q;
pt[0]=0;
}
}
main()
{int m,h;
char s[10][10],p[120];
printf("Please enter m:");
scanf("%d",gets(s[0]);
printf("Please enter%d string:",m);
for(h=0;h<m;h++)gets(s[h]);
fun(s,m,p);
printf("The result is:%s",p);
}
问答题给定程序中,函数fun的功能是:利用指针数组对形参ss所指字符串数组中的字符串按由长到短的顺序排序,并输出排序结果。ss所指字符串数组中共有N个字符串,且串长小于M。
请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
#define N 5
#define M 8
void fun(char (*ss)[M])
{ char *ps[N],*tp; int i,j,k;
for(i=0; i
for(i=0; i
/**********found**********/
k= __1__ ;
for(j=i+1; j
/**********found**********/
if(strlen(ps[k]) < strlen(__2__) ) k=j;
/**********found**********/
tp=ps[i]; ps[i]=ps[k]; ps[k]= __3__ ;
}
printf("/nThe string after sorting by length:/n/n");
for(i=0; i
}
main()
{ char ch[N][M]={"red","green","blue","yellow","black"};
int i;
printf("/nThe original string/n/n");
for(i=0;i
fun(ch);
}
问答题编写函数proc(),它的功能是求m以内(不包括m)同时能被5与11整除的所有自然数之和的平方根s,并作为函数值返回。
例如,m为100时,函数值应为s=7.416198。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<math.h>
#include<stdio.h>
double proc(int n)
{
}
void main()
{
system("CLS");
printf("s=%f/n",proc(100));
}
问答题基本操作
函数fun的功能是:在有n个元素的结构体数组std中,查找有不及格科目的学生,找到后输出学生的学号;函数的返回值是有不及格科目的学生人数。例如,主函数中给出了4名学生的数据,则程序运行的结果为:
学号:N1002 学号:N1006
共有2位学生有不及格科目
请在程序的下划线处填入正确的内容,并把下划线删除,使程序得出正确的
结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include
typedef struct
{ char num[8];
double score[2];
/**********found**********/
} __(1)__ ;
int fun(STU std[ ], int n)
{ int i, k=0;
for(i=0; i