Pages

Friday 2 November 2012

UVA - 11636 - Hello World! (C Solution)

#include <stdio.h>

int main()
{
    int x,j,i,q,res;
    int arr[16];
    arr[0]=0;
        for(i=1,q=1;i<16;i++,q*=2){
            arr[i]=q;
        }
    i=1;
    while(1){
        scanf("%d",&x);
        if(x<0){
            break;
        }
        for(j=0;j<16;j++){
              if(arr[j]>=x){
                  res=j-1;
                  break;
              }
          }
         printf("Case %d: %d\n",i,res);
         i++;
    }
    return 0;
}

No comments:

Post a Comment