Guest User

Untitled

a guest
Oct 17th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <stdio.h>
  4. #include <string>
  5. #include <cmath>
  6. using namespace std;
  7.  
  8. int check(int n)
  9. {
  10. int s=n;
  11. while (s%2==0)
  12. {
  13. s/=2;
  14.  
  15. }
  16. if (s==1)
  17. return 1;
  18. else
  19. return 0;
  20. }
  21.  
  22. void main(void)
  23. {
  24. int i=0,a[10]={0},n;
  25. while(1)
  26. {
  27. cin>>n;
  28. if (n==0)
  29. break;
  30. if (n==1)
  31. {
  32. a[i]=1;
  33. }
  34. else
  35. {
  36. if (check(n)==1)
  37. a[i]=(int)(log((double)n)/log(2.0));
  38. else
  39. a[i]=(int)(log((double)n)/log(2.0)+1);
  40. }
  41. i++;
  42.  
  43. }
  44. for (int j=0;j<i;j++)
  45. printf("%d \n",a[j]);
  46. }
Add Comment
Please, Sign In to add comment