题目
在主函数中,从键盘输入若干个数放入数组x中,用0结束输入但不计入数组。下列给定程序中,函数fun()的功能是:输出数组元素中小于平均值的元素。请补充函数fun()。
例如:数组中元素的值依次为1,2,2,12,5,15,则程序的运行结果为1,2,2,5。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<conio.h>
include<stdio.h>
void fun(【 】,int n)
{
double sum=0.0;
double average=0.0;
int i=0;
for(i=0;i<n;i++)
【 】;
average= 【 】;
for(i=0;i<n;i++)
if(x[i]<average)
{
if(i%5==0)
printf("\n");
printf("%d/",x[i]);
}
}
main()
{
int x[1000];
int i=0;
clrscr();
printf("\nPlease enter some data(end with 0):");
do
{
scanf("%d",&x[i]);
}
while(x[i++]!=0);
fun(x,i-1);
}
第1题
请补充函数fun(),该函数的功能是:返回字符数组中指定子符的个数,指定字符从键盘输入。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
define N 80
int fun (char s[],char ch)
{
int i=0, n=0;
while(【 】)
{
if(【 】)
n++;
i++;
}
【 】;
}
main ()
{
int n;
char str[N], ch;
clrscr ();
printf ("\nInput a string: \n");
gets (str);
printf ("\nInput a charactor: \n" ;
scanf ("%c", &ch);
n=fun (str, ch);
printf("\nnumber of %c:%d", ch, n);
}
第2题
从键盘输入一组无符号整数并保存在数组arr[N]中,以整数0结束输入,即第N+1个数是0,要求这些数的最大位数不超过4位,其元素的个数通过变量num传人函数proc()。请补充函数proc(),其功能是:从数组arr中找出个位和十位的数字之和大于5的所有无符号整数,结果保存在数组yy中,其个数由函数proc返回。
例如,当arr[8]={13,1,205,252,2,333,4444,21)时实际输人时,数与数之间用Enter键分开,bb[4]={252,333,4444)。
注意:部分源程序给出如下。
请勿改动函数main()和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
试题程序:
第3题
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<ctype.h>
main()
{
int i=0;
char a [81];
char *p=s;
clrscr ();
printf{" Input a string \n");
for (i=0; i<80; i++)
{
s [i] =getchar ();
if (s [i]=='\n')
【 】;
}
s[i]=【 】
printf(" display the string \n");
while (*p)
putchar (【 】);
}
第4题
请编写函数void fun(int x, int pp[], int *n),它的功能是:求出能整除x且不是偶数的各整数,并按从小到大的顺序放在即所指的数组中,这些除数的个数通过形参n返回。
例如,若x中的值为30,则有4个数符合要求,它们是1, 3,5,15。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
void fun (int x, int pp[], int *n)
{
}
main()
{
int x,aa[1000], n, i ;
clrscr();
printf("\nPlease enter an integer
number : \n ") ;
scanf ("%d", &x) ;
fun (x, aa, &n) ;
for (i=0 ; i<n ; i++)
printf ("%d ", aa [i]);
printf ("\n ") ;
}
第5题
请补充函数proc(),该函数的功能是把数组num中的数按从小到大的顺序排列(数组元素个数及值从主函数中输入)。
例如,输入n=5,num[0]~num[4]依次为5 7 2 8 0,结果为0 2 5 7 8。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
试题程序:
第6题
请补充函数fun(),该函数的功能是;删除字符数组中小于等于指定字符的字符,指定字符从键盘输入,结果仍保存
例如,输入“abcdefghij”,指定字符为‘d’,则结果输出“defghij”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio. h>
define N 80
void fun (char s[], char ch)
{
int i=0, j=0;
while (s [i] )
{
if (s Iii<ch)
【 】;
else
{
【 】
i++;
}
}
【 】
}
main ()
{
char str [N], ch;
clrscr ();
printf("\n Input a string:\n");
gets (str);
printf("\n*** original string ***\n");
puts (str);
printf("\n Input a character:\n");
scanf ("%c", &ch);
fun(str, ch);
printf("\n*** new string ***\n");
puts (str);
}
第7题
例如,输入:-3847652,结果为:3847652。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
main()
{
long int n;
clrscr();
printf("Enter the data;\n");
scanf(【 】);
printf("*** the absolute value ***\n");
if(n<0)
【 】
printf("\n\n");
printf(【 】);
}
第8题
请补充函数fun(),该函数的功能是:从键盘输入一个下标n,把数组aa中比元素aa[n]小的元素放在它的左边,比它大的元素放在它的右边,排列成的新数组仍然保存在原数组中。
例如,数组aa={33,67,42,58,25,76,85,16,41, 56},输入3。
结果输出“33,42,25,16,41,56,58,67,76,85”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仪在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
define N 10
void fun(int aa[],int n)
{
int i,j=0,k=0,t;
int bb[N];
t=aa[n];
for(i=0;i<N;i++)
{
if(aa[i]>t)
bb[j++]=aa[i];
if(aa[i]<t)
aa[k++]=aa[i];
}
【 】;
for(i=0;【 】;i++, k++)
aa[k]=bb[i];
}
main()
{
int i,n;
int aa[N]={33,67,42,58,25,76,85,16,41,56};
clrscr();
printf("\n*** original list ***\n");
for(i=0;i<N;i++)
printf("%4d"/aa[i]);
printf("\n suffix n\n");
scanf("%d",&n);
fun(aa,n);
printf("\n*** new list ***\n");
for (i=0;i<N; i++)
printf("%4d", aa[i]);
}
第9题
例如,如果输入strl;=“abced”,str2=“fk”,则输出“fkced”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仪在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<string. h>
main ()
{
char strl [ 81], str2 [ 81 ];
char *pl=strl, *p2=str2;
clrscr ();
do
{
printf(" Input strl tn");
gets (strl);
printf(" Input str2 In");
gets (str2);
}while(【 】);
while(【 】)
*p1++=*p2++;
printf(" Display strl \n");
puts (【 】)
}
第10题
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!