prog8.c
来自「c题库」· C语言 代码 · 共 35 行
C
35 行
/*
编写函数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);
}
/*
答案:
int i;
float s=1.0,t=1.0;
for(i=2;i<=n;i++)
{ t=t+i;
s=s+1/t;
}
return s;
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?