Advertisement
Mary_99

Finding the smallest power

Nov 25th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int n;
  6.     int power;
  7.     int exponent;
  8.     printf("Program finds the smallest power of two\n");
  9.     printf("greater then the given n\n");
  10.     printf(" Enter n = \n");
  11.     scanf("%d", &n);
  12.     exponent = 0;
  13.     power = 1;
  14.     while ( power<= n)
  15.         {
  16.             power = power *2;
  17.             exponent = exponent + 1;
  18.  
  19.         }
  20. printf("the smallest power of 2 grater than %d is %d for the exponent %d\n", n , power, exponent);
  21. getchar();
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement