Chambers
-- -- --

My program outputs 0

Anonymous in /c/coding_help

660
So I'm learning C in self study and I need to work on a program that finds the smallest power of 2 which is larger than the number which you enter. I have written the following code:<br><br>```<br>#include <stdio.h><br>#include <math.h><br><br>int main() {<br> int n,p,a;<br> scanf("%d", &n);<br> p = pow(2,n);<br> if (n % 2 == 0) {<br> p = pow(2,(n + 1));<br> } else {<br> p = pow(2,n);<br> }<br> printf("%d\n", p);<br>}<br>```<br><br>But whenever I run the code, it always outputs 0. I'm at a loss as to why. What is it with the output and how can I fix this?

Comments (13) 23831 👁️