| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:请大家帮忙改一下, 为什么不停的运行呢?In Reply To:请大家帮忙改一下, 为什么不停的运行呢? Posted by:piaofushi919 at 2004-11-24 08:38:25 > #include <stdio.h>
> #include <math.h>
> void main()
> {
> float a,sum;
> int n,c;
> while (a!=0.00)
> {
> scanf("%.2f",&a);
> c=0;
> sum=0;
> for(n=2;n<67;n++)
> {
> if (sum<a)
> sum+=1/n;
> c=c+1;
> if(sum>a)
> break;
> }
> printf("%d\n card(s)",c);
> }
> }
因为n是整型数,故1/n=>(int)(1/n)=0;应该改为sum+=(float)1/n.也就是
(float)1/n=>1.0000/n=(float)型数。
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator