Quantcast
Channel: How to check if a number is a power of 2 - Stack Overflow
Viewing all articles
Browse latest Browse all 38

Answer by udhaya for How to check if a number is a power of 2

$
0
0

Find if the given number is a power of 2.

#include <math.h>int main(void){    int n,logval,powval;    printf("Enter a number to find whether it is s power of 2\n");    scanf("%d",&n);    logval=log(n)/log(2);    powval=pow(2,logval);    if(powval==n)        printf("The number is a power of 2");    else        printf("The number is not a power of 2");    getch();    return 0;}

Viewing all articles
Browse latest Browse all 38

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>