填空题
请补充函数proc(),该函数的功能是:删除字符数组中小于指定字符的字符,指定字符从键盘输入,结果仍保存在原数组中。
例如,输入“abcdefghij”,指定字符为“f”,则结果输出“fghij”。
注意:部分源程序已给出。
请勿改动主函数main和其他甬数中的任何内容。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#define M 80
void proc(char str[], char ch)
int i=0, j=0;
while(str[i])
if(str[i]<ch)
(1) ;
else
(2) ;
i++;
(3) ;
void main()
char str[N], ch;
system("CLS");
printf("\n Input a string: \n");
gets(str);
printf("\n***original string***\n");
puts(str);
printf("n Input a charactor:\n");
scanf("%c", &ch);
proc(str, oh);
printf("\n***new string***\n");
puts(str);
【参考答案】
str[j]=’\0’
热门
试题
填空题
下列给定程序中,函数proc()的功能是:从m个学生的成绩中统计出低于平均分的学生人数,人数由函数值返回,平均分存放在形参aver所指的存储单元中。例如输入8名学生的成绩: 60 70 80 90 65 75 85 95 则低于平均分的学生人数为4(平均分为77.5)。实际输入时学生数以回车键作为结束,成绩与成绩之间也与回车键作为分隔。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #inelude<stdlib.h> #include<stdio.h> #include<conio.h> #define M 20 int proc (float *s, int n, float * aver) ************found************* int ave, t=0; int count=0, k, i; for(k=0; k<n; k++) t+=s[k]; ave=t n; for(i=0; i<n; i++) ************found************ if(s[i]>ave) count++; ************found************* aver=ave; return count; void main() float stu[30], aver; int m, i; system( CLS ); printf( nPlease enter m: ); scanf( %d , &m); printf( nPlease enter%d mark: n , m); for(i=0; i<m; i++) scanf( %f , stu+i); printf( nThe number of students: %d n , proc(stu, m, &aver)); printf( Ave=%f n , aver);