1.scanf()的用法,见百度百科;
2.scanf用来接收小数,把输入变量声明为float不行,声明为double就可以了,scanf里%f不行,但是%lf就行了。
#include <stdio.h> int main() { double sum, in; int num; while(scanf("%lf", &in) != EOF) { if(in == 0.00) break; num = 1; sum = 0.5; while(sum < in) { num ++; sum += (float)1/(num+1); } printf("%d %s\n", num, "card(s)"); } return 0; }