Advertisement
Me-Alex

Afisare 2^n=... pt oricare n

Oct 22nd, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. #define MAX 32
  6.  
  7. int n, v[MAX], i, cat,t;
  8.  
  9. int main()
  10. {
  11. cout << "n= ";
  12. cin >> n;
  13. t=n;
  14. v[0] = v[1] = 1;
  15.  
  16. while(n != 0) // Cat timp mai avem de inmultit
  17. {
  18. i = 1;
  19. cat = 0; // Initializam "cat" si "i"
  20.  
  21. while(i <= v[0] || cat != 0)
  22. {
  23. v[i] = v[i] * 2 + cat;
  24. cat = v[i] / 10;
  25. v[i] %= 10;
  26. v[0] = max(v[0], i);
  27. i++;
  28. }
  29.  
  30. n--;
  31. }
  32.  
  33. cout << "2^"<<t<<"=";
  34.  
  35. for(i = v[0]; i >= 1; i--)
  36. {
  37. cout << v[i];
  38. }
  39.  
  40.  
  41.  
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement