现在的位置: 首页 > 综合 > 正文

poj1003——HangOver

2017年11月21日 ⁄ 综合 ⁄ 共 263字 ⁄ 字号 评论关闭

大致题意:输入一个数X,求1/2 + 1/+ 1/4 + ... + 1/(N+ 1)>=X时最小N的值。

 #include <stdio.h>
 int main()
 {
       
 	float a;
 	float sum=0.0;
	int count;
 	while(scanf("%f",&a)!=EOF&&a!=0.0)
    {
		count=2;
 		sum=0;
 		while(sum+=(1.0/count))
 		{
 			if(sum<a)
 		 count++;
 		 else break;

 		 }
 		 printf("%d card(s)",count-1);
 		 printf("\n");
    }
 	return 0;
}

抱歉!评论已关闭.