Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int potegowanie(int x, int y)
  4. {
  5. int i, wynik = 1;
  6. for(i = 0; i < y; i++)
  7. {
  8. wynik *= x;
  9. }
  10. return wynik;
  11. }
  12.  
  13. int main()
  14. {
  15. int n, wykladnik = 0, ilosc = 0;
  16. printf("Podaj liczbe: ");
  17. scanf("%d", &n);
  18.  
  19. while(n > 1)
  20. {
  21. wykladnik = 0;
  22. while(potegowanie(2, wykladnik) <= n)
  23. {
  24. wykladnik++;
  25. }
  26. wykladnik--;
  27. ilosc++;
  28. n = n - potegowanie(2, wykladnik);
  29. }
  30.  
  31. if(n == 1)
  32. {
  33. ilosc++;
  34. }
  35.  
  36. int liczba = 0;
  37.  
  38.  
  39. printf("Ilosc poteg dwojki: %d", ilosc);
  40.  
  41.  
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement