1.m个人的成绩存放在score数组中,请编写函数fun,它的功能是:将低于平均分的人数作为函数值返回,将低于平均分的分数放在below所指的数组中。
例如,当score数组中的数据为10、20、30、40、50、60、70、80、90时,函数返回的人数应该是4,below中的数据应为10、20、30、40。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
#include
#include
#include
int fun(int score[],int m, int below[])
{
}
main()
{
int i,n,below[9];
int score[9]={10,20,30,40,50,60,70,80,90};
clrscr();
n=fun(score,9,below);
printf(“\nBelow the average score are :”);
for(i=0;i
printf(“%d “,below[i]);
}
8.编写函数fun,函数的功能是:根据以下公式计算s,计算结果作为函数值返回;n通过形参传入。
S=1+1/(1+2)+1/(1+2+3)+……1/(1+2+3+…+n)
例如:若n的值为11时,函数的值为1.833333。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
#include
#include
#include
float fun (int n)
{
}
main()
{
int n;
float s;
clrscr();
printf(“\nPlease enter N:”);
scanf(“%d”,&n);
s=fun(n);
printf(“The result is: %f\n”,s);
}
改错题:
1.下列给定程序的功能是:读入一个整数k(2≤k≤10000),打印它的所有质因子(即所有为素数的因子)。例如,若输入整数2310,则应输出:2、3、5、7、11。
请改正程序中的错误,使程序能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include “conio.h”
#include “stdio.h”
/********found********/
IsPrime ( int n ) ;
{
int i, m;
m=1;
/********found********/
for(i=2;i
if !(n%i)
{
m=0;
break;
}
return(m);
}
main()
{
int j, k;
clrscr();
printf(“\nplease enter an integer number between 2 and 10000:”);
scanf(“%d”,&k);
printf(“\n\nThe prime factor(s) of %d is(are):”,k);
for(j=2;j
if((!(k%j))&&(IsPrime(j)))
printf(” %4d,”,j);
printf(“\n”);
}
6.下列给定程序中,函数fun的功能是:根据整型形参m的值,计算如下公式的值。
1 1 1
T=1- ― – - -… -
2×2 3×3 mxm
例如,若m中的值为5,则应输出:0.536389。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include
#include
double fun(int m)
{
double y=1.0;
int i;
/********found********/
for(i=2;i
/********found********/
y-=1/(i*i);
return(y);
}
main()
{
int n=5;
clrscr();
printf(“\nThe result is %1f\n”,fun(n));
}