问答题规定输入的字符串中只包含字母和*号。编写函数fun,其功能是:除了字符串前导和尾部的*号外,将串中其他的*号全部删除。形参h已指向字符串中第一个字母,形参P指向字符串中最后一个字母。在编写函数时,不得使用C语言提供的字符串函数。 例如,若字符串中的内容为“****A*BC*DEF*G*******”,删除后,字符串中的内容应当是“****ABCDEFG*******”。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序: #include<stdio.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 after deleted:/n"); puts(s);
问答题下列给定程序中,函数fun的功能是:依次取出字符串中所有的数字字符,形成新的字符串,并取代原字符串。 请改正函数fun中的错误,使它能得出正确的结果。 注意:不得增行或删行,也不得更改程序的结构! 试题程序:#include<stdlib.h>#include<stdio.h>#include<eonio.h>void fun(char*s){ int i,j; for(i=0,j=0;s[i]1=‘\0’;i++) if(s[i]>=‘0’&&s[i]<=‘9’)/*******found*******/ s[j]=s[i];/*******found*******/ s[j]=“\0”;}void main(){ char item[80]; system(“CLS”); prinff(“\nEnter a string:”); gets(item); prinff(“\nThe string is:%s\n”,item); fun(item); printf(“\nThe string of changing is:%s\n”,item);}
问答题下列给定程序中,函数fun的功能是:将s所指字符串中最后一次出现的与t1所指字符串相同的子串替换成t2所指字符串,所形成的新串放在w所指的数组中。要求t1和t2所指字符串的长度相同。例如,当S所指字符串中的内容为“abcdabfabc”,t1所指串中的内容为“ab”,t2所指子串中的内容为“99”时,结果在w所指的数组中的内容应为“abcdabt99c”。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<conio.h>#include<stdio.h>#include<string.h>void fun(char *s,char t1,char t2,char w){ char*P,*r,*a; strcpy(w,S);/*********found*********/ while(w) { p=W; r=t1; while(*r)/*********found*********/ IF(*r==*P) { r++; p++; } else { break; } if(*r=='\0') a=w; w++; } r=t2; while(*r) { *a=*r; a++; r++; }}main(){ char s[100],t1[100],t2[100],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("\nError: strlen(t1)!=strlen(t2)\n"); }}
问答题请编写函数fun(),它的功能是计算:s=(1-ln(1)-ln(2)-ln(3)-…-ln(m))2 s作为函数值返回。 在C语言中可调用log(n)函数求ln(n)。log函数的引用说明是double log(double x)。 例如,若m的值为15,则fun()函数值为723.570801。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include <conio.h> #include <stdio.h> #include <math.h> double fun(int m) { } main() { clrscr(); printf("%f/n",fun(15)); }
问答题下列给定程序中,函数fun和funx的功能是:用二分法求方程2x3-4x2+3x-6=0的一个根,并要求绝对误差不超过0.001。 例如,若给m输入-100,n输入90,则函数求得的一个根为2.000。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include<sfdio.h> #include<math.h> double funx(double x) [return(2*X*X*X-4*x*x+3*x-6);] double fun(double m,double n) /*******found********/ int ;;r=(m+n)/2; /********found********/ while(fabs(n-m)<0.001) ifcfunx(r)*funx(n)<0)m=r; else n=r; r=(m+n)/2; return r; main() double m,n,root; printf("Enter m n:/n"); scanf("%lf%lf", root=fun(m,n); printf("root=%6.3f/n",root);
问答题学生的记录由学号和成绩组成,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},
/TAB /TAB {"GA01",91},{"GA07",72},{"GA08",64},{"GA06",87},
/TAB /TAB {"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91},
/TAB /TAB {"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);
for(i=0;i
printf("%s M/n",h[i].num,h[i].s);
printf("/n");
out = fopen("c://test//out.dat","w") ;
fprintf(out, "%d/n",n);
for(i=0;i
fprintf(out, "M/n",h[i].s);
fclose(out);
}
问答题给定程序MODIl.C中函数fun的功能是:从整数1到55之间,选出能被3整除、且有一位上的数是5的那些数,并把这些数放在b所指的数组中,这些数的个数作为函数值返回。规定,函数中a1放个位数,a2放十位数。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 #include<stdio.h> int fun(int *b) { int k,a1,a2,i=0; for(k=10;k<=55;k++){ /**********found**********/ a2=k/10; a1=k-a2*10; if((k%3==0&&a2==5)‖(k%3==0&&a1==5)) {b[i]=k;i++;} } /**********found**********/ return k: } main() { int a[100],k,m; m=fun(a); printf("The result is:\n"); for(k=0;k<m;k++)printf("%4d",a[k]);printf("\n"); }
问答题给定程序MODIl.C中,函数fun的功能是:在有11名学生,2门课成绩的结构体数组std中,计算出第1门课程的平均分,作为函数值返回。例如,主函数中给出了4名学生的数据,则程序运行的结果为:第1门课程的平均分是:76.125000 请改正函数fun中指定部位的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。#include <stdio.h>typedef struct{char num[8];double score[2];}STU;double fun(STU std[],int n){int i;/**********found**********/ double sum;/**********found**********/ for(i=0;i<2;i++)/**********found**********/sum+=std[i].score[1];return sum/n;)main(){STU std[]={"N1001",76.5,82.0,"N1002",66.5,73.0,"N1005",80.5,66.0,"N1006",81.0,56.0);printf("第1门课程的平均分是:%lf\n",fun(std,4));}
问答题请编写函数fun(),该函数的功能是:实现B=A+A',即把矩阵A加上A的转置,存放在矩阵B中。计算结果在main()函数中输出。
例如,输入下面矩阵:
1 2 3
4 5 6
7 8 9
其转置矩阵为:
1 4 7
2 5 8
3 6 9
则程序输出:
2 6 10
6 10 14
10 14 18
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
#include<conio.h>
void fun (int a[3][3], int b[3][3])
{
}
main ()
{
int a[3][3]={{1,2,3}, {4,5,6},{7,8,9}},t[3] [3];
int i, j;
clrscr ();
fun (a,t);
for(i=0; i<3; i++)
{ for (j=0; j<3; j++)
printf ("%7d",t [i] [j] );
printf ("/n");
}
}
问答题下列给定程序中,函数proc()的功能是:依次取出字符串中所有的数字字符,形成新的字符串,并取代原字符串。例如原始字符串是“ab45c6djfd789”,则输出后的字符是“456789”。
请修改函数proc()中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void proc(char*s)
{int i, j;
for(i=0, j=0; s[i]!="/0"; i++)
if(s[i]>="0"
//****found****
s[j]="/0";
}
void main()
{char str[80];
system("CLS");
printf("/nEnter a string:"); gets(str);
printf("/n/nThe string is:%s/n", str);
proc(str);
printf("/n/nThe siring of changing is: %s/n", str);
}
问答题学生的记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组s中,请编写函数fun,其功能是:把分数最高的学生数据放在b所指的数组中。注意:分数最高的学生可能不止一个,函数返回分数最高的学生人数。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序: #include<stdio.h> #define N 16 typedef struct char num[10]; int s; STREC; int fun(STREC*a,STREC*b) void 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; 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");
问答题请编一个函数fun(char*s),该函数的功能是:把字符串中的内容逆置。
例如,字符串中原有的字符串为“abcdefg”,则调用该函数后,串中的内容为“gfedcba”。
注意
:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<string.h>
#include<conio.h>
#include<stdio.h>
#define N 81
void fun(char *s)
{
}
main()
{
char a[N];
printf("Enter a string:");
gets (a);
printf("The original string is:");
puts(a);
fun(a);
printf("/n");
printf("The string after modified:");
puts(a);
strcpy(a,"Hello world!");
fun(a);
}
问答题给定程序中,函数fun的功能是:有N×N矩阵,根据给定的m(m
#define N 4
void fun(int (*t)[N] , int m)
{ int i, j;
/********** found**********/
for(i=0; i=0; j--)
/********** found**********/
t[i] [j+【2】]=t[i] [j];
/**********found**********/
for(j=0; j<【3】; j++)
t[i] [j]=0;
}
}
main ()
{ int t[][N]={21,12,13,24,25,16,
47,38,29,11,32,54,42,21,33,10},
i, j, m;
printf("/nThe original array:/n");
for(i=0; i
问答题试编写函数fun(),其功能是计算并输出n(包括n)以内能被5或9整除的所有自然数的倒数之和。 例如,在主函数中从键盘给n输入20后,输出为s=0.583333。 注意:要求n的值不大于100。 #include<stdio.h> double fun(int n) main() int n;double s; printf("/nInput n:");scanf("%d", s=fun(n); printf("/n/ns=%f/n",s);
问答题请编写函数。fun能是:判断形参n中的正整数是几位数(输入数据的位数不超过4位),并将结果通过函数值返回。例如:若输入的数据为l23,则输出结果为:输入的数字是3位。注意:部分源程序存在PROGl.C中,请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所缩写的若干语句。试题程序:
问答题假定输入的字符串中只包含字母和*号。请编写函数fun,它的功能是:除了字符串前导的*号之外,将串中其它 “*”号全部删除。在编写函数时,不得使用C语言提供的字符串函数。函数fun中给出的语句仅供参考。
例如,字符串中的内容为:****A*BC*DEF*G******,删除后字符串中的内容应当是:****ABCDEFG。
注意:部分源程序在文件PROG1.C文件中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include
voici fun( char *a )
{
/*以下代码仅供参考*/
int i=0,k;
while(a[i]=='*') i++;
k=i;
while(a[i]!='/0')/*以下程序段实现
非*字符前移*/
{
}
a[k]='/0';
}
main()
{ char s[81]; void NONO();
printf ("Enter a string:/n"); gets (s);
fun( s );
printf( "The string after
deleted: /n"); puts (s);
NONO();
}
void NONO ()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/
FILE *in, *out;
int i;char s[81];
in =fopen( "in.dat","r");
out =fopen( "out.dat","w");
for(i=0;i<1 0;i++){
fscanf (in,"ooS",s);
fun (s);
fprintf (out,/;%s/n/;,s),
}
fclose (in);
fclose (out);
}
问答题请编写函数fun(),它的功能是:求出1到1000之内能被5或13整除、但不能同时被5和13整除的所有整数并将它们放在a所指的数组中,通过n返回这些数的个数。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include <conio.h> #include <stdio.h> void fun(int *a,int *n) main( ) int aa[1000],n,k; clrscr( ); fun(aa,&n); for(k=0;k<n;k++) if((k+1)%10==0) printf("%5d",aa[k]); printf("/n"); /*—行写10个数*/ else printf("%5d",aa[k]);
问答题下列给定程序中,函数fun的功能是:将自然数1一10及其平方根写到名为myfile3.txt的文本文件中,然后再顺序读出显示在屏幕上。
请在程序下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<math.h>
#include<stdio.h>
int fun(char*fname)
{ FILE*fp;int i,n;float x;
if ((fp=fopen(fname,"w"))
==NULL)
return 0,
for(i=1;i<=10;i++)
/*********found*********/
fprintf(
【1】
,"%d%f\n",i,sqrt((double)i));
printf("\nSucceed!!\n");
/*********found*********/
【2】
;
printf("\nThe data in file:\n");
/*********found*********/
if((fp=fopen(
【3】
,"r"))==
NULL)
return 0;
fscanf(fp,"%d%f",&n,&x);
while(!feof(fp))
{ printf("%d%f\n",n,x);
fscanf(fp,"%d%f",&n,&x);)
fclose(fp);
return 1;
}
main()
{ char fname[]="myfile3.txt";
fun(fname);
}
问答题下列给定程序中函数fun的功能是:判断一个整数是否为素数,若是素数返回1,否则返回0。在main函数中,若fun返回1输出YES,若fun返回0输出NO!。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<stdlib.h>#include<conio.h>#include<stdio.h>int fun(intm){ int k=2; while(k<=m&&(m%k))/*********found*********/ k++/*********found*********/ if(m=k) return 1; else return 0 ;}void main(){ int n; system("CLS"); printf("\nplease enter n:"); scanf("%d",&n); if(fun(n))printf("YES\n"); else printf("NO!\n");}
问答题学生的记录由学号和成绩组成,M名学生的数据已在主函数中放入结构体数组stu中,请编写函数proc(),它的功能是:把指定分数范围内的学生数据放在b所指的数组中,分数范围内的学生人数由函数值返回。 例如,输入的分数是70和79,则应当把分数在70到79的学生数据进行输出.包含70分和79分的学生数据。主函数中把70放在low中,把79放在heigh中。 注意:部分源程序已给出。 请勿改动主函数main和其他函数中的任何内容,仅在函数proc的花括号中填入所编写的若干语句。 试题程序: #include<stdio.h> #define M 16 typedef struct char num[10]; int s; STREC: int proc(STREC*a,STREC*b,int 1,int h) void main() STREC stu[M]="GA005",85,"GA003",76, "GA002",69,"GA004",85,"GA001",96, "GA007",72,"GA008",64,"GA006",87, "GA015",85,"GA013",94,"GA012",64, "GA014",91,"GA011",90,"GA017",64, "GA018",64,"GA016",72; STREC h[M]; int i,n,low,heigh,t; printf("Enter 2 integer number low &heigh:"); scanf("%d%d",&low,&heigh); if(heigh<low) t=heigh;heigh=low;low=t; n=proc(stu,h,low,heigb); printf("The student's data between %d--%d:/n",low,heigh); for(i=0;i<n;i++) printf("%s%4d/n",h[i].num,h[i].s); //输出指定分数范围内的学生记录 printf("/n");
