八次求和c语言程序,C语言程序设计100例之(7):级数求和

本文介绍了使用C语言求解级数求和问题,包括找到最小的n使得1+1/2+1/3+...+1/n > k,以及计算纸牌悬挑的最大长度、π的值和e的近似值。通过循环和简单的数学公式,实现了程序计算这些值的方法。
摘要由CSDN通过智能技术生成

例7    级数求和

题目描述

已知: Sn =1+1/2+1/3+…+1/n。显然对于任意一个整数 k,当 n 足够大的时候,Sn>k。

现给出一个整数 k,要求计算出一个最小的 n,使得 Sn>k。

输入格式

一个正整数 k

输出格式

一个正整数 n

输入样例

1

输出样例

2

(1)编程思路。

用简单的循环完成多项式求和。循环控制条件为和S<=K。

(2)源程序。

#include

int main()

{

int k,n;

double s;

s=0;

n=0;

scanf("%d",&k);

do {

n++;

s+=1.0/n;

}while (s<=k);

printf("%d\n",n);

return 0;

}

习题3

7-1  Deck

本题选自北大POJ题库 (http://poj.org/problem?id=1607)

Description

A single playing card can be placed on a table, carefully, so that the short edges of the card are parallel to the table's edge, and half the length of the card hangs over the edge of the table. If the card hung any further out, with its center of gravity off the table, it would fall off the table and flutter to the floor. The same reasoning applies if the card were placed on another card, rather than on a table.

Two playing cards can be arranged, carefully, with short edges parallel to table edges, to extend 3/4 of a card length beyon

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值