网站的按钮怎么做,合肥动画制作公司,那个网站可以看高速的建设情况,群晖做网站服务器 套件一、程序填空题
在此程序中#xff0c;函数fun的功能是#xff1a;在形参s所指字符串中寻找与参数c相同的字符#xff0c;并在其后插入一个与之相同的字符#xff0c;若找不到相同的字符则不做任何处理。
例如#xff0c;若s所指字符串”baacda”#xff0c;中c的字符为…一、程序填空题
在此程序中函数fun的功能是在形参s所指字符串中寻找与参数c相同的字符并在其后插入一个与之相同的字符若找不到相同的字符则不做任何处理。
例如若s所指字符串”baacda”中c的字符为a执行后s所指字符串为”baaaacdaa”。
#include stdio.h
void fun(char *s, char c)
{ int i, j, n;
/**********found**********/ for(i0; s[i]!___1___ ; i) if(s[i]c) {
/**********found**********/ n___2___ ; while(s[i1n]!\0) n; for(jin1; ji; j--) s[j1]s[j];
/**********found**********/ s[j1]___3___ ; ii1; }
}
void main()
{ char s[80]baacda, c; printf(\nThe string: %s\n,s); printf(\nInput a character: ); scanf(%c,c); fun(s,c); printf(\nThe result is: %s\n,s);
}
答案(1) 0 (2) 0 (3) c
二、程序修改题
在此程序中主函数从键盘输入若干个数放入数组中用0结束输入并放在最后一个元素中。下列给定程序中函数fun的功能是计算数组元素中所有值为正数的平均值(不包括0)。
例如数组中元素中的值依次为39,-47,21,2,-8,15,0则程序的运行结果为19.250000。
#include stdio.h
double fun ( int x[])
{
/************found************/ int sum 0.0; int c0, i0; while (x[i] ! 0) { if (x[i] 0) { sum x[i]; c; } i; }
/************found************/ sum \ c; return sum;
}
void main( )
{ int x[1000]; int i0; printf( \nPlease enter some data (end with 0): ); do { scanf(%d, x[i]); } while (x[i] ! 0); printf(%f\n, fun ( x ));
}
答案(1) double sum 0.0; (2) sum / c;
三、程序设计题
在此程序中编写函数fun其功能是根据以下公式计算s并计算结果作为函数值返回n通过形参传入。 例如若n的值为11时函数的值为1.833333。
#include stdio.h
float fun(int n)
{ }
void main()
{ int n; float s; void NONO ( ); printf(\nPlease enter N:); scanf(%d, n); s fun(n); printf(the result is: %f\n, s); NONO();
}
void NONO ( )
{/* 本函数用于打开文件输入数据调用函数输出数据关闭文件。 */ FILE *fp, *wf ; int i, n ; float s; fp fopen(in.dat,r) ; wf fopen(out.dat,w) ; for(i 0 ; i 10 ; i) { fscanf(fp, %d, n) ; s fun(n) ; fprintf(wf, %f\n, s) ; } fclose(fp) ; fclose(wf) ;
}
答案
int i,s10;
float s0.0;
for(i1;in;i)
{s1s1i; /*求每一项的分母*/
ss1.0/s1; /*求多项式的值*/
}
return s;