Monday 27 July 2015

HANGOVER

Hangover

 Link to the question : HANGOVER

HINT :

Just simply find the sum of the series given in the question : 1/2 + 1/3 +...1/k. till the sum is less than equal to the input, n. Keep a count  of the k.

RECOMMENDED QUESTION :

Try solving this question after completing this.

SOURCE CODE :

#include<stdio.h>
int main()
{
    float s,n,x=1,i;
    while(x!=0)
    {
        scanf("%f",&n);
        x=n;
        if(x!=0)
        {
            s=0;i=2;
            while(s<=n)
            {
                s=s+1/i;

                i++;
            }
            printf("%1.0f card(s)\n",i-2);
        }
    }
    return 0;
}

No comments:

Post a Comment