Search Here

Saturday, May 16, 2015

UVa - 10940 - ( Throwing cards away II Solve ) [ C Code ]

Tip : Try Yourself First . It's an easy problem . For Help Scroll Down .


Code :

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define S(a) scanf("%d",&a)
#define P(a) printf("%d\n",a)

int main()
{
    int n, p, calc, l;
    while(S(n)==1)
    {
        if(n==0) break;
        l = (int)((log (n))/(log (2.0)));
        p = pow(2,l);
        calc = (n-p);
        if(p==n)
            P(n);
        else
            P(2*calc);
    }
    return 0;
}

=> Questions ?? Leave A Comment .I Used Here Macro Statement .


No comments:

Post a Comment