here is only basic implementation of problems for beginners. If you have any problem with any solution or any basic concept of programming or you want more efficient solution you can mail me.
my suggestion is not to copy and paste codes from here try to understand the logic and think why you were not able to solve it.

Thursday, 11 September 2014

Hangover

#include<stdio.h>
int main(){
    float a,sum,i,p;
    while(1){
    sum=0;
        scanf("%f",&a);
        if(a==0.00)
        break;
        for(i=2;i<277;i++){
            sum=sum+(1/i);
            if(sum>a){
                printf("%.0f card(s)\n",i-1);
                break;
            }
                                 
        }
    }
    return 0;
}
                                 
                                  

2 comments:

  1. Hi, I've used sum>a as loop termination condition, you have used condition i<277 in, what 277 means here ?

    thanks in advance

    ReplyDelete
    Replies
    1. actually u can see from test cases that for 0 max 273 cards can be used. so i just checked for all cards one by one :)

      Delete