POWER OF 2
Problem Description
Ram challenges Ganga to write a code to check whether an Integer Number is power of two (2) or not. Can you help Ganga to come out of this problem.
CODING ARENA
#include <stdio.h>
int main()
{
int num;
int tempNum,flag;
scanf("%d",&num);
tempNum=num;
flag=0;
/*check power of two*/
while(tempNum!=1)
{
if(tempNum%2!=0){
flag=1;
break;
}
tempNum=tempNum/2;
}
if(flag==0)
printf("YES");
else
printf("NO");
return 0;
}
Test Case 1
Input (stdin)32
Expected Output
YES
Test Case 2
Input (stdin)36
Expected Output
NO
No comments:
Post a Comment