mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-12-16 15:44:39 +00:00
39 lines
654 B
Markdown
39 lines
654 B
Markdown
# 6-1 计算A[n]=1/(1 + A[n-1])
|
||
|
||
函数 fun 的功能是:根据整型形参 n,计算某一数据项的值。
|
||
A[1]=1, A[2]=1/(1 + A[1]), A[3]=1/(1 + A[2]), …,A[n]=1/(1 + A[n-1])
|
||
例如,若 n=10,则应输出:A10=0.617977。
|
||
|
||
### 函数接口定义:
|
||
```c++
|
||
float fun(int n);
|
||
```
|
||
|
||
其中`n`是用户传入的参数,函数须返回第`n`项的值。
|
||
|
||
### 裁判测试程序样例:
|
||
```c++
|
||
#include <stdio.h>
|
||
float fun(int n);
|
||
int main( )
|
||
{ int n ;
|
||
scanf("%d", &n ) ;
|
||
printf("A%d=%f\n", n, fun(n) ) ;
|
||
return 0;
|
||
}
|
||
|
||
|
||
/* 请在这里填写答案 */
|
||
```
|
||
|
||
### 输入样例:
|
||
```in
|
||
10
|
||
```
|
||
|
||
### 输出样例:
|
||
```out
|
||
A10=0.6180
|
||
|
||
```
|