问答题下列给定程序中,函数fun()的功能是求出数组中最小数和次最小数,并把最小数和a[0]中的数对调,次最小数和a[1]中的数对调。 请改正程序中的错误,使它能得到正确结果。 [注意] 不要改动main函数,不得增行或删行,也不得更改程序的结构。 [试题源程序] #include <stdio.h> #include <conio.h> #define N 20 void fun(int *a, intn) int i, m, t, k; /************************found************************/ for(i=0; i<n; i++) m=i; for(k=i; k<n; k++) if(a[k]<a[m]) /************************found************************/ k=m; t=a[i]; a[i]=a[m]; a[m]=t;
问答题请编写函数proc(),它的功能是计算:
s=(ln(1)+ln(2)+ln(3)+…+ln(m))0.5
在C语言中可调用log(n)函数求ln(n)。
例如,若m的值为30,则proc()函数值为8.640500。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
double proc(int m)
{
}
void main()
{
system("CLS");
printf("%f/n", proc(30));
}
问答题假定输入的字符串中只包含字母和''*''号。请编写函数fun,它的功能是:使字符串中尾部的''*''号不得多于n个;若多于n个,则删除多余的''*''号;若少于或等于n个,则什么也不做,字符串中间和前面的''*''号不删除。 例如,字符串中的内容为:**8*A*BC*DEF*G*******,若n的值为4,删除后,字符串中的内容应当是:****A*BC*DEF*G****;若n的值为7, 则字符串中的内容仍为:****A*BC*DEF*G*******。n的值在主函数中输入。在编写函数时,不得使用C语言提供的字符串函数。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。1 #include<stdio.h>2 void fun(char *a,int n)3 {45 }6 main()7 { char s[81];int n;8 void NONO();9 printf(''Enter a string:\n'');gets(s);10 printf(''Enter n:'');scanf("%d", puts(s);13 NONO();14 }15 void NONO()16 {/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */17 FILE *in,*out;18 int i,n ; char s[81];19 in=fopen(''in.dat'',''r'');20 out=fopen(''out.ctat'',''w'');21 for(i=0;i<10 ; i++) {22 fscanf(in,''%s'',s);23 fscanf(in,''%d'',&n);24 fun(s,n);25 fprintf(out,''%s\n'',s);26 }27 fclose(in);28 fclose(out);29 }
问答题下列给定程序中,函数fun的功能是:根据整型形参m,计算如下公式的值:例如,若m的值为5,则应输出1.463611。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<conio.h>#include<stdio.h>doublefun(intm)doubley=1.0;inti;/********fOund********/for[i=2;i<m;i++)/********found********/y+=1/(i*i);return(y);main()intn=5;printf("/nTheresultis%lf/n",fun(n));
问答题编写函数fun,其功能是:删除一个字符串中指定下标的字符。其中,a指向原字符串,删除指定字符后的字符串存放在b所指的数组中,n放指定的下标。 例如,输入一个字符串“world”,然后输入3,则调用该函数后的结果为“word”。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序: #include<stdlib.h> #include<stdio.h> #include<conio.h> #define LEN 20 void fun(char a[],har b[],int n) void main() char strl[LEN],str2[LEN]; int n; system("CLS"); printf("Enter the string:/n"); gets(str1); printf("Enter the position of the string deleted:"); scanf("%d", fun[str1,str2,n); printf("The new string is:%s/n",str2);
问答题请编写函数fun, 函数的功能是: 将M行N列的二维数组中的字符数据, 按列的
顺序依次放到一个字符串中。
例如, 二维数组中的数据为:
W W W W
S S S S
H H H H
则字符串中的内容应是: WSHWSHWSH。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容, 仅在函数fun的花括号中填入
你编写的若干语句。
给定源程序:
#include
#define M 3
#define N 4
void fun(char s[][N], char *b)
{
int i,j,n=0;
for(i=0; i < N;i++) /* 请填写相应语句完成其功能 */
{
}
b[n]='\0';
}
main()
{ char a[100],w[M][N]={{'W','W','W','W'},{'S','S','S','S'},{'H','H','H','H'}};
int i,j;
printf("The matrix:\n");
for(i=0; i
问答题规定输入的字符串中只包含字母和*号。请编写函数fun,其功能是:使字符串中尾部的*号不多于n个,若多于n个,则删除多余的*号;若少于或等于n个,则不做任何操作,字符串中间和前面的*号不删除。
例如,字符串中的内容为“****A*BC*DEF*G*******”,若n的值为4,删除后,字符串中的内容应为“****A*BC*DEF*G****”;若n的值为7,则字符串中的内容仍为“****A*BC*DEF*G*******”。n的值在主函数中输入。编写函数时,不得使用C语言提供的字符串函数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include <stdio.h>
void fun(char*a,int n)
{
}
main()
{ char s[81]; int n;
printf("Enter a string:\n");
gets(s);
printf("Enter n:");
scanf("%d",
fun(s,n);
printf("The string after deleted:\n");
puts(s);
}
问答题给定程序MODI1.C中函数 fun 的功能是: 读入一个字符串(长度<20 ),将该字符串中的所有字符按ASCII码升序排序后输出。
例如, 若输入: edcba, 则应输出: abcde。
请改正程序中的错误,使它能统计出正确的结果。
注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
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( "/nPlease enter a character string: " );
gets( s );
printf( "/n/nBefore sorting:/n /"%s/"", s );
fun( s );
printf( "/nAfter sorting decendingly:/n /"%s/"", s );
}
问答题请编写一个函数fun,它的功能是:比较两个字符串的长度,(不得调用C语言提供的求字符串长度的函数),函数返回较长的字符串。若两个字符串长度相同,则返回第一个字符串。 例如,输入beijing<CR>shanghai<CR>(<CR>为回车键),函数将返回shanghai。 注意:部分源程序存在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。1 #include<stdio.h>2 char *fun(char *s,char *t)3 {4 }5 main()6 { char a[20],b[20];7 void NONO();8 printf(''Input:1th string:'');9 gets(a);10 printf(''Input 2th string :'');11 gets(b);12 printf(''%s\n'',fun(a,b));13 NONO();14 }15 void NONO()16 {/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */17 FILE *fp,*wf;18 int i;19 char a[20],b[20];20 fp=fopen(''in.dat'',''r'');21 wf=fopen(''out''.dat'',''w'');22 for(i=0;i<10;i++){23 fscanf(fp,''%s%s'',a,b);24 fprintf(wf,''%s\n'',fun(a,b));25 }26 fclose(fp);28 fclose(wf); }
问答题给定程序MODI1.C中函数fun的功能是:将s所指字符串中出现的与t1所指字符串相同的子串全部替换成t2所指字符串,所形成的新串放在w所指的数组中。在此处,要求t1和t2所指字符串的长度相同。
例如,当s所指字符串中的内容为:"abcdabfab",t1所指子串中的内容为:"ab",t2所指子串中的内容为:"99"时,结果在w所指的数组中的内容应为:"99cd99f99"。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
#include<stdio.h>
#include<string.h>
void fun(char*s,char*t1,char*t2,char*w)
{
char*p,*r,*a;
strcpy(w,s);
while(*w)
{p=w;r=t1;
/**********found**********/
while(r)
if(*r==*p){r++;p++;}
else break;
if(*r=="/0")
{a=w;r=t2;
while(*r){
/**********found**********/
*a=*r;a++;r++
}
w+=strlen(t2);
}
else w++:
}
}
main()
{
chars[100],t1[100],t2[1003,w[100];
printf("/nPlease enter string S:");scanf("%s",s);
printf("/nPlease enter substring t1:");scanf("%s",t1);
printf("/nPlease enter substring t2:");scanf("%s",t2);
if(strlen(t1)==strlen(t2)){
fun(s,t1,t2,w);
printf("/nThe result is:%s/n",w);
}
else printf("Error:strlen(t1)!=strlen(t2)/n");
}
问答题请编写函数fun,函数的功能是:将放在字符串数组中的M个字符串(每串的长度不超过N),按顺序合并组成一个新的字符串。 例如,字符串数组中的M个字符串为 AAAA BBBBBBB CC 则合并后的字符串的内容应是:AAAABBBBBBBCC。 提示:strcat(a,b)的功能是将字符串b复制到字符串a的串尾上,成为一个新串。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。1 #include<stdio.h>2 #include<string.h>3 #define M 34 #define N 205 void fun(char a[M][N],char *b)6 {78 }9 main()10 { char w[M][N]={''AAAA'',''BBBBBBB'',''CC''},a[100];11 int i;void NONO();12 printf(''The string:\n'');13 for(i=0 ; i<M;i++)puts(w[i]);14 printf(''\n'');15 fun(w,a);16 printf(''The A string:\n'');17 printf(''%s'',a);printf(''\n\n'');18 NONO();19 }20 void NONO()21 {/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/22 FILE *rf,*wf ;23 char w[M][N],a[100];int i;24 rf=fopen(''in.dat'',''r'');25 wf=fopen(''out.dat'',''w'');26 for(i=0;i<10;i++) {27 fscanf(rf,''%s%s%s'',w [0],w[1], w [2]);28 fun(w,a);29 fprintf(wf,''%s\n'',a);30 }31 fclose(rf);fclose(wf);32 }
问答题改错题
下列给定程序中,函数fun()的功能是逐个比较a,b两个字符串对应位置中的字符,把ASCII值小或相等的字符依次存放到c数组中,形成一个新的字符串。
例如:a中的字符串为fshADfg,b中的字符串为sdAEdi,则c中的字符串应为fdAADf。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
void fun(char *p,char *q,char *c)
{ int k=0;
while(*p||*q)
/**********************found***********************/
{ if (*p<=*q)
c[k]=*q;
else c[k]=*p;
if(*p) p++;
if(*q) q++ ;
/**********************found***********************/
k++
}
}
main()
{ char a[10]="fshADfg",b[10]="sdAEdi",c[80]={''/0''};
fun(a,b,c);
printf("The string a:"); puts(a);
printf("The string b:"); puts(b);
printf("The result :"); puts(c);
}
问答题请编写一个函数fun, 其功能是: 将ss所指字符串中所有下标为奇数位置上的字母转换为大写(若该位置上不是字母, 则不转换)。
例如, 若输入"abc4EFg",则应输出"aBc4EFg"。
注意: 部分源程序在文件PROG1.C文件中。
请勿改动主函数main和其它函数中的任何内容, 仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
#include
void fun( char *ss )
{
}
void main( void )
{
char tt[51];
printf( "/nPlease enter an character string within 50 characters:/n" );
gets( tt );
printf( "/n/nAfter changing, the string/n /"%s/"", tt );
fun(tt) ;
printf( "/nbecomes/n /"%s/"", tt );
NONO();
}
问答题下列给定程序中,fun()函数的功能是:求3个数的最小公倍数,例如,给变量a、b、c、分别输入15、11、2,则输出结果应当是330。
请修改函数中的错误,得出正确的结果。
注意:不要改动main()函数,不能增行或减行,也不能更改程序的结构。
试题程序:
#include<stdio.h>
int fun(int x, int y, int z)
{
int i, temp, n, m;
//****found****
i=1;
temp=m=n=1;
//****found****
while(temp!=0
temp=i%x;
m=i%y;
n=i%z;
}
return i;
}
void main()
{
int a, b, c, i;
printf("Input a b c: ");
scanf("%d%d%d",
printf("a=%d, b=%d, c=%d/n", a, b, c);
i=fun(a, b, c);
printf("The minimal common multiple is: %d/n", i);
}
问答题给定程序MODI1.C中函数fun的功能是:将tt所指字符串中的小写字母都改为对应的大写字母,其他字符不变。 例如,若输入''Ab,cD'',则输出''AB,CD''。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 #include<string.h>3 char* fun(char tt[])4 {5 int i;6 for(i=0;tt[i];i++)7 /**********found**********/8 if(('a'<=tt[i])||(tt[i]<='z'))9 /**********found**********/10 tt[i]+=32;11 return(tt);12 }13 main()14 {15 char tt[8 1];16 printf(''\nPlease enter a string:'');17 gets(tt);18 printf(''\nThe result string is:\n%s'',fun(tt));19 }
问答题编写程序,实现矩阵(3行、3列)的转置(即行列互换)。例如,若输入下面的矩阵:100 200 300400 500 600700 800 900则程序输出:100 400 700200 500 800300 600 900注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:1 #include<stdio.h>2 #include<conio.h>3 #include<stdlib.h>4 void fun(int array[3][3])5 {67 }8 void main()9 {10 FILE,lc Wf;11 int i,j;12 int array[3][3]={{100,200,300),{400,500,600),{700,800,900});13 system("CLS");14 for(i=0;i<3;i++)15 { for(j=0;j<3;J++)16 printf("%7d",array[i][j]);17 printf("\n");18 }19 fun(array);20 printf("Converted array:\n");21 for(i=0;i<3;i++)22 { for(j=0;j<3;j++)23 printf("%7d",array[i][j]);24 printf("\n");25 }26 /*********found*********/27 wf=fopen(”out.dat”,”w”);28 for(i=0;i<3;i++)29 { for(j=0;j<3;j++)30 fprintf(wf,"%7d",array[i][j]);31 fprintf(wf,"\n");32 }33 fclose(wf);34 /*********found*********/35 }
问答题假定输入的字符串中只包含字母和*号。请编写函数fun,它的功能是:除了尾部的*号之外,将字符串中其他木号全部删除。形参p已指向字符串中最后的一个字母。在编写函数时,不得使用c语言提供的字符串函数。 例如, 字符串中的内容为:****A*BC*DEF*G*******,删除后,字符串中的内容应当是:ABCDEFG*******。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。1 #include<stdio.h>2 void fun(char *a,char *p)3 {4 }5 main()6 { char s[81],*t ;7 void NONO();8 printf(''Enter a string:\n'');gets(s);9 t=s;10 while( *t)t++;11 t--;12 while(*t=='*')t--;13 fun(s,t);14 printf(''The string after deleted:\n'');puts(s);15 NONO();16 }17 void NONO()18 {/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */19 FTLE *in,*out;20 int i;char s[81],*t;21 in=fopen(''in.dat'',''r'');22 out=fopen(''out.dat'',''w'');23 for(i=0;i<10;i++) {24 fscanf(in,''%s'',s);25 t=s;26 while(*t)t++;27 t--;28 while(*t=='*')t--;29 fun(s,t);30 fprintf(out,''%s\n'',s);31 }32 fclose(in);33 fclose(out);}
问答题请编写函数fun,函数的功能是: 移动字符串中的内容,移动的规则如下: 把第1到第m个字符, 平移到字符串的最后, 把第m+1到最后的字符移到字符串的前部。
例如, 字符串中原有的内容为: ABCDEFGHIJK, m的值为3, 则移动后, 字符串中的内容应该是: DEFGHIJKABC。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容, 仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
#include
#define N 80
void fun1(char *w) /* 本函数的功能是将字符串中字符循环左移一个位置 */
{
int i; char t;
t=w[0];
for(i=0;i
w[i]=w[i+1];
w[strlen(w)-1]=t;
}
void fun(char *w, int m) /* 可调用fun1函数左移字符 */
{
}
main()
{ char a[N]= "ABCDEFGHIJK";
int m;
printf("The original string:/n");puts(a);
printf("/n/nEnter m: ");scanf("%d",
fun(a,m);
printf("/nThe string after moving:/n");puts(a);
printf("/n/n");
NONO();
}
问答题程序通过定义学生结构体变量,存储学生的学号、姓名和三门课的成绩。函数fun的功能是:将形参a中的数据进行修改,把修改后的数据作为函数值返回主函数进行输出。
例如,若传给形参a的数据中学号、姓名和三门课的成绩依次是:10001、“ZhangSan”、95、80、88,修改后的数据应为:10002、“LiSi”、96、81、89。
请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<string.h>
struct Student{
long sno;
char Flame[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 stuclent s={10001,"ZhangSan",95,80,88},t;
int i;
printf ("\n\nThe original data:\n");
printf("\nNo:%ld Name:%s\n Scores:",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\n Scores:",t.sno,t.name);
for(i=0;i<3;i++)
printf("%6.2f",t.score[i]);
printf("\n");
}
问答题程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(inta[][N],intn),该函数的功能是:使数组左下半三角元素中的值乘以n。例如,若n的值为3,a数组中的值为:则返回主程序后a数组中的值应为:注意:部分源程序给出如下。请勿改动函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdio.h>#include<conio.h>#include<stdlib.h>#defineN5voidfun(inta[][N],intn){}main(){inta[N][N],n,i,j;printf("*****Thearray*****/n");for(i=0;i<N;i++){for(j=0;j<N;j++){a[i][j]=rand()%10;printf("%4d",a[i][j]);}printf("/n");}n=rand()%4;printf("n=%4d/n",n);fun(a,n);printf("*****THERESULT*****/n");for(i=0;i<N;i++){for(j=0;j<N;j++)printf("%4d",a[i][j]);printf("/n");}}
