Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int potegowanie(int x, int y)
- {
- int i, wynik = 1;
- for(i = 0; i < y; i++)
- {
- wynik *= x;
- }
- return wynik;
- }
- int main()
- {
- int n, wykladnik = 0, ilosc = 0;
- printf("Podaj liczbe: ");
- scanf("%d", &n);
- while(n > 1)
- {
- wykladnik = 0;
- while(potegowanie(2, wykladnik) <= n)
- {
- wykladnik++;
- }
- wykladnik--;
- ilosc++;
- n = n - potegowanie(2, wykladnik);
- }
- if(n == 1)
- {
- ilosc++;
- }
- int liczba = 0;
- printf("Ilosc poteg dwojki: %d", ilosc);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement