Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6.  
  7. int cifre(int n) {
  8. if (n == 0) return 0;
  9. return 1 + cifre(n / 10);
  10. }
  11. // Rasturnatul
  12. int rast(int n, int p) {
  13. if (n == 0) return 0;
  14. return (n % 10) * pow(10, p) + rast(n / 10, p - 1);
  15. }
  16.  
  17. // N nr. suma
  18.  
  19. int numar(int n) {
  20. if (n == 0) return 0;
  21. int x; cin >> x;
  22. return x + numar(n - 1);
  23. }
  24.  
  25. // divizor care conform algo euclid va calcula divizorul comun, 0 si 0 nu exista
  26. int gcd(int a, int b) {
  27. if (b == 0)
  28. return a;
  29. return gcd(b, a % b);
  30. }
  31. int32_t main() {
  32. int n, m, a, b, x;
  33. cin >> n >> m >> a >> b;
  34. cout << "cifre(n) = " << cifre(n) << endl;
  35. cout << "cifre(m) = " << cifre(m) << endl;
  36. cout << "rast(n) = " << rast(n, cifre(n) - 1) << endl;
  37. cout << "rast(m) = " << rast(m, cifre(m) - 1) << endl;
  38. cout << "numar(n) = " << numar(n) << endl;
  39. cout << "euclid(a, b) = " << gcd(a, b) << endl;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement