Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

判断一个浮点数是否为0不能直接与0比较!我在注释里指出了错误。

Posted by hz02ruc at 2003-11-21 16:04:24 on Problem 1003
In Reply To: 兄弟,帮个忙吧,为什么输入0以后还显示运算结果呢? Posted by:211211 at 2003-11-21 15:13:09
> #include<stdio.h>
> #include<math.h>
> void main(){
> 	int  i;
> 	float a ; // 加上 scanf("%f",&a);
>      while (a!=0.00) {             //改成while(fabs(a)>0.000001)
>        	                          //判断一个浮点数a是否为0
         scanf ("%f",&a);     //这句去掉!!
         int    m=0;
> 	float  sum=0;
> 	for    (i=2;i<276;i++){
>    	if    (sum<a) 
> 		   sum+=float(1./i);
> 	       m+=1;
> 	if     (sum>=a) break;
> 	}
> 	printf("%d\n",m);//此句后加上 scanf("%f",&a);
> 	}
> 	
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator