栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > 资讯 > 高等教育 > 考研政策

期末了,看看这些c语言的题都能做出来吗?(1)

期末了,看看这些c语言的题都能做出来吗?(1)

1. There is a sequence of fractions:2/1,3/2,5/3,8/5,13/8,21/13... Find the sum of the first 20 items of this sequence。

#include "stdio.h"

#include "stdlib.h"

int main()

{

int n, t, number = 20;

double a = 2, b = 1, s = 0;

for (n = 1; n <= number; n++)

{

s = s + a / b;

t = a;

a = a + b;

b = t;

}

printf("The sum is %.3lfn", s);

printf("nnn");

system("pause");

return 0;

}

2. There is a sequence of fractions:1/3,3/5,5/7,7/9...,Find the sum of the first 10 items of this sequence

#include "stdio.h"

#include "stdlib.h"

int main()

{

int i;

double n = 1, sum = 0;

for (i = 0; i < 10; i++)

{

sum += n / (n + 2);

n = n + 2;

}

printf("nsum=%.3f。n", sum);

printf("nnn"); system("pause")return 0;}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/news/1542655.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号