Run Code  | API  | Code Wall  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

Answer for last midterm question

//gcc 5.4.0

#include  <stdio.h>
int main(void)
{
 int num, result, counter;
 printf("Enter a positive number:\n");
 scanf("%d", &num);
 result = 1;
 counter = 1;
    //Do we need the counter? Why or why not?
 if (num != 0)
     for (counter=1; counter<=num; counter++) {
 result *= 2;
 } 
 printf("Two raised to the %d power is:%d\n", num, result);

}
 run  | edit  | history  | help 0