请编写一个函数fun(),它的功能是计算并输出给定整数n的所有因子(不包括1与自身)的平方和(规定n的值不大于100)。
例如:主函数从键盘给输入n的值为56,则输出为 sum=1113。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
long fun(int n)
{
}
main()
{
int n;
long sum;
printf("Input n:");
scanf("%d",&n);
sum=fun(n);
printf("sum=%ld\n",sum);
}
第1题:
请编写一个函数fun(),它的功能是计算并输出给定整数n的所有因子(不包括1与自身)之和(规定n的值不大于1000)。
例如:输入n的值为856,则输出为sum=763。
注意:部分源程序已存在文件test33_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数count的花括号中填写若干语句。
文件test33_2.cpp清单如下:
include<stdio. h>
include<iostream. h>
int fun(int n)
{
}
void main ( )
{
int n, sum;
cout<<"Input n:"<<end1;
cin>>n;
sum=fun (n);
cout<<" sum= \n"<<sum<<end1;
}
第2题:
请补充函数fun(),函数fun()的功能是求7的阶乘。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
long fun(int n)
{
if(【 】)
return(n*fun(【 】);
else if(【 】)
return 1;
}
main()
{
int k=7;
printf("%d!=%ld\n", k, fun(k));
}
第3题:
编写函数fun(),它的功能是求n以内(不包括n)同时能被3与7整除的所有自然数之和的平方根s,并做为函数值返回。例如:n为1000时,函数值应为s=153.909064。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <math.h>
include <stdio.h>
double fun(int n)
{
}
main()
{
clrscr();
printf("s=%f\n", fun(1000));
}
第4题:
请编写函数fun(),它的功能是计算下列级数和,和值由函数值返回。
S=1+x+x2/2!3/3!+…/xn/n!
例如,当n=10,x=0.3时,函数值为1349859。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。
试题程序:
include<conio.h>
include<stdio.h>
include<math.h>
double fun(double x, int n)
{
}
main ()
{
clrscr ();
printf ("%f ",fun(0,3,10));
}
第5题:
请编写函数fun(),其功能是:计算并输出下列多项式的值。
S=1+4/(1+2)+1/(1+2+3)+…+1/(1+2+3+…+n)
例如,着主函数从键盘给n输入50后,则输出为 S=1.960784。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
double fun(int n)
{
}
main ()
{
int n;
double s;
printf ("\nInput n: ");
scanf ("%d", &n);
s=fun (n);
printf ("\n\ns=%f\n\n", s);
}
第6题:
请编写函数fun,它的功能是:计算并输出n(包括n)以内能被5或9整除的所有自然数的倒数之和。
例如,在主函数中从键盘给n输入20后,输出为:s=0.583333。注意:要求n的值不大于100。
部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
第7题:
请编写函数fun(),它的功能是计算下列级数和,和值由函数值返回。
S=1-x+x2(上标)/2!-x3(上标)/3!+…+ (-1*x) n(上标)/n!
例如,当n=15,x=0.5时,函数值为0.606531。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio.h>
include<stdio.h>
include<math.h>
double fun(double x, int n)
{
}
main()
{
clrscr();
printf("%f ",fun (0.5,15));
}
第8题:
请编写函数fun(),它的功能是计算:s=(1-In(1)-In(2)-In(3)-…-1n(m))2
s作为函数值返回。
在C语言中可调用log(n)函数求In(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));
}
第9题:
请编写函数fun,其功能是:计算并输出下列多项式的值:
例如,在主函数中从键盘给n输入50后,输出为:s=1.718282。
注意:要求n的值大于1但不大于100。部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
第10题:
请编写函数fun( ),其功能是:将所有大于1小于整数m的素数存入xx所指数组中,素数的个数通过k传回。
例如,输入25,则应输出2 3 5 7 11 13 17 19 23。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio.h>
include<stdio.h>
void fun(int m,int *k,int xx[ ])
{
}
main( )
{
int m,n,zz[100];
clrscr( );
printf("/nPlease enter an integer number between 10 and 100:");
scanf("%d",&n);
fun(n,&m,zz);
printf("\n\nThere are%d prime numbers
less than %d:",m,n);
for(n=0;n<m;n++)
printf("\n %4d",zz[n]);
}
第11题:
请补充函数fun(),该函数的功能是计算下面公式SN的值:
例如:当N=50时,SN=71.433699。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<conio.h>
include<stdio.h>
double fun(int n)
{
double s=1.0,S1=0.0;
int k;
for(【l】;k<=n;k++)
{
s1=s;
【 】;
}
return【 】;
}
main()
{
int k=0;
double S;
clrscr();
printf("\nPlease input N=");
scanf("%d",&k);
s=fun(k);
printf("\ns=%lf",s);
}
第12题:
第13题:
请补充函数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);
}
第14题:
请编写函数fun(),其功能是;计算井输出下列多项式值。
S=(1-1/2)+(1/3-1/4)+…+(1/(2n-1)-1/2n)
例如,若主函数从键盘给n输入8后,则输出为 S-0.662872。
注意;部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。
试题程序;
include<stdio. h>
double fun(int n)
{
}
main ()
{
int n;
double s;
printf("\nInput n: ");
scanf ("%d", &n);
s=fun (n);
printf ("\ns=%f\n ", s);
}
第15题:
请补充main 函数,该函数的功能是:计算两个自然数n和m(m<10000)之间所有数的和(n和m从键盘输入)。
例如:当n=1,m=100时,sum=5050:当n=100,m=1000时,sum=495550。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main 函数的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
main ()
{
int n, m;
long sum;
【 】
clrscr ();
printf ("\nInput n,m\n");
scanf ("%d, %d", &n, &m);
while (n<=m)
{
【 】
n++;
}
printf ("sum=%【 】\n", sum);
}
第16题:
请编写一个函数void fun(int m, int k, int xx[]),该函数的功能是将大于整数m且紧靠m的k个非素数存入所指的数组中。
例如,若输入15,5,则应输出16,18,20,21,22。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio.h>
include<stdio.h>
void fun(int m,int k,int xx[])
{
}
main()
{
int m,n,zz[1000];
clrscr();
printf("\nPlease enter two integers:");
scanf("%d%d",&m,&n);
fun(m,n,zz);
for(m=0;m<n;m++)
printf("%d",zz[m]);
printf("\n");
}
第17题:
编写函数fun(),函数的功能是:根据以下公式计算s,计算结果作为函数值返回;n通过形参传入。
S=1+1/(1+2)+1/(1+2+3)+…+1/(1+2+3+…+n)
例如:若n的值为11时,函数的值为1.833333。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
include <string.h>
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);
}
第18题:
请编写函数fun(),它的功能是求Fibonacci数列中小于t的最大的一个数,结果由函数返回。其中Fibonacci数列F(n)的定义为
F(0)=0,F(1)=1
F(n)=F(n-1)+F(n-2)
例如:t=1000时,函数值为987。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <math.h>
include <stdio.h>
int fun(int t)
{
}
main()
{
int n;
clrscr();
n=1000;
printf("n=%d, f=%d\n",n, fun(n));
}
第19题:
编写函数fun(),它的功能是求n以内(不包括n)同时能被5与11整除的所有自然数之和的平方根s,并作为函数值返回。
例如:n为1000时,函数值应为s=96.979379。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <math.h>
include
double fun(int n)
{
}
main()
{
clrscr();
printf("s=%f\n",fun(1000));
}
第20题:
请编写一个函数fun(),它的功能是将一个数字字符串转换为一个整数(不得调用C语言提供的将字符串转为整数的函数)。
例如,若输入字符串“-1234”,则函数把它转换为整数值 -1234。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
include <string.h>
long fun(char *p)
{
}
main ( )
{
char s[6];
long n;
printf("Enter a string:\n");
gets(s);
n=fun(s);
printf("%ld\n",n);
}
第21题:
请编写函数fun(),其功能是:计算并输出下列多项式值。
S=(1+1/2)+(1/3+1/4)+…+(1/(2n-1)+l/2n)
例如,若主函数从键盘给n输入12后,则输出为 S=3.775958。
n的值要求大于1但不大于100。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<stdio.h>
double fun(int n)
{
}
main()
{
int n;
double s;
printf("\nlnput n:");
scanf("%d",&n);
s=fun(n);
printf("\ns=%f\n",s);
}
第22题:
请编写函数fun(),该函数的功能是:计算并输出
S=1+(1+20.5)+(1+20.5+30.5)+…+(1+20.5+30.5+…+n0.5)
例如,若主函数从键盘给n输入20后,则输出为
s=534.188884。
注意;部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。
试题程序:
include <math. h>
include <stdio. h>
double fun(int n)
{
}
main()
{
int n;
double s;
printf("\n\nInput n: ");
scanf ("%d", &n);
s=fun (n)
printf ("\n\ns=%f\n\n", s);
}
第23题:
请编写函数fun,其功能是:计算并输出
例如,在主函数中从键盘给n输入20后,输出为:s=534.188884。
注意:要求n的值大于1但不大于100。
部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。