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:snowfall at 2008-03-22 18:03:35 > #include<iostream.h> > main() > { > float c,n,p; > cin>>c; > while(c!=0) > { for(n=1,p=0;p<c;n++) > p=p+(1/(n+1)); > cout<<(n-1)<<" "<<"card(s)\n";cin>>c;} > } > > > #include<stdio.h> > main() > { > float n,c,p; > > scanf("%f",&c); > > while(c!=0) > { > for(n=1,p=0;p<c;n++) > { p=p+(1/(n+1)); > } > printf("%g card(s)\n",(n-1)); > scanf("%f",&c); > } > } > > > 一个是C,一个是C++,代码一样,结果怎么就不一样呢 把用C写的“平日那头发“printf("%d card(s)\n",(n-1) );" 改为”printf("%d card(s)\n",(n-1) );" 就可以了 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator