aimon1337

Untitled

Apr 6th, 2021 (edited)
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. // 1
  2. #include <iostream>
  3. using namespace std;
  4. int main() {
  5.     unsigned int a, b;
  6.     cin >> a >> b;
  7.     if (a > b) {
  8.         cout << a << " este mai mare decat " << b << ", ";
  9.         return 0;
  10.     } else {
  11.         if (b == a) {
  12.             cout << "numere egale, ";
  13.             return 0;
  14.         } else {
  15.             cout << b << " este mai mare decat " << a << ". ";
  16.             return 0;
  17.         }
  18.     }
  19.     return 0;
  20. }
  21. // 2
  22. int f(int a, int b) {
  23.     if ((a % 2 == 0) && (b % 2 == 0)) {
  24.         return a + b;
  25.     } else {
  26.         if ((a % 2 == 1) && (b % 2 == 1))
  27.             return a - b;
  28.         else
  29.             return a * b;
  30.     }
  31. }
  32. // 3
  33. #include <iostream>
  34. using namespace std;
  35. int f(int x) {
  36.     if (x <= 3)
  37.         return (x > 1);
  38.     if (x % 2 == 0 || x % 3 == 0)
  39.         return 0;
  40.     for (int i = 5; i * i <= x; i = i + 6) {
  41.         if (x % i == 0 || x % (i + 2) == 0)
  42.             return 0;
  43.     }
  44.     return 1;
  45. }
  46. int main() {
  47.     int a;
  48.     cin >> a;
  49.     if(f(a)==1)
  50.         cout<<a<<" este prim.";
  51.     else cout<<a<<" nu este prim.";
  52.     return 0;
  53. }
Add Comment
Please, Sign In to add comment