Vladi1442

Untitled

Feb 15th, 2022
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int a, b;
  8.     cin >> a >> b;
  9.    
  10.     if(a == 0){
  11.         if(b == 0){
  12.             cout << "INF" << endl;
  13.         } else {
  14.             cout << "No solution!" << endl;
  15.         }
  16.     } else {
  17.         cout << "x = " << - b / a << endl;
  18.     }
  19.    
  20.     int n;
  21.     cin >> n;
  22.    
  23.     int i = 1;
  24.     int f = 1;
  25.    
  26.     if(i <= n){
  27.         f *= i;
  28.         i++;
  29.     } else {
  30.         cout << f << endl;
  31.     }
  32.  
  33.     int a, b;
  34.     cin >> a >> b;
  35.    
  36.     if(a == 0 || b == 0){
  37.         cout << "Error" << endl;
  38.     } else {
  39.         if(a == b){
  40.             cout << a << endl;
  41.         } else {
  42.             if(a > b){
  43.                 cout << a = a - b;
  44.             } else {
  45.                 cout << b = b - a;
  46.             }
  47.         }
  48.     }
  49.    
  50.     int quotient, remainder, a, b;
  51.    
  52.     cout << "Enter divisor: " << endl;
  53.     cin >> a;
  54.    
  55.     cout << "Enter dividend: " << endl;
  56.     cin >> b;
  57.    
  58.     quotinet = a / b;
  59.     remainder = a % b;
  60.    
  61.    
  62.     cout << "Quotient: " << quotient << endl;
  63.     cout << "Remaineder: " << remainder << endl;
  64.    
  65.    
  66.     cout << "The size of int: " << sizeof(int) << endl;
  67.     cout << "The size of double: " << sizeof(double) << endl;
  68.     cout << "The size of bool: " << sizeof(bool) << endl;
  69.     cout << "The size of char: " << sizeof(char) << endl;
  70.     cout << "The size of long: " << sizeof(long) << endl;
  71.     cout << "The size of short: " << sizeof(short) << endl;
  72.     cout << "The size of long double: " << sizeof(long double) << endl;
  73.    
  74.     // swapping numbers
  75.    
  76.     int num1, num2;
  77.     cin >> num1 >> num2;
  78.    
  79.     cout << "Before swapping numbers: " << endl;
  80.     cout << "First number = " << num1 << "\n" << "Second number = " << num2 << endl;
  81.    
  82.     int temp = num1;
  83.     num1 = num2;
  84.     num2 = temp;
  85.    
  86.     cout << "After swapping numbers: " << endl;
  87.     cout << "First number = " << num1 << "\n" << "Second number = " << num2 << endl;
  88.  
  89.     // even or odd number
  90.    
  91.     int n;
  92.     cin >> n;
  93.    
  94.     if(n % 2 == 0){
  95.         cout << "Even number! " << endl;
  96.     } else if(n % 2 != 0) {
  97.         cout << "Odd number! "
  98.     }
  99.    
  100.     // check whether character is a consonant or vowel
  101.    
  102.     char symbol;
  103.     cin >> symbol;
  104.    
  105.     if(symbol == 'a' || symbol == 'e' || symbol == 'i' || symbol == 'u' || symbol == 'o' || symbol == 'A' || symbol == 'E' || symbol == 'I' || symbol == 'O' || symbol == 'U'){
  106.         cout << "Character is a vowel" << endl;        
  107.     } else {
  108.         cout << "Character is a consonant " << endl;
  109.     }
  110.  
  111.     // roots of quadratic equations
  112.    
  113.     int a, b, c, D;
  114.     cin >> a >> b >> c;
  115.    
  116.     D = b * b - 4 * a * c;
  117.    
  118.     if(D > 0){
  119.         cout << "x1 = " << ((- b - sqrt(D)) / 2 * a);
  120.         cout << "x2 = " << ((- b + sqrt(D)) / 2 * a);
  121.     } else if(D == 0){
  122.         cout << "x1 = x2 = " << - b / (2 * a) << endl;
  123.     } else {
  124.         cout << "x1 = " << - b / (2 * a) << endl;
  125.     }
  126.  
  127.     int a, b, c;
  128.     cin >> a >> b >> c;
  129.  
  130.     if(a > b && a > c){
  131.         cout << "Largest number is: " << a << endl;
  132.     } else if(b > a && b > c){
  133.         cout << "Largest number is: " << b << endl;
  134.     } else {
  135.         cout << "Largest number is: " << c << endl;
  136.     }
  137.  
  138.     // check whether the year is Leap
  139.    
  140.     int year;
  141.     cin >> year;
  142.    
  143.     bool isLeap = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
  144.    
  145.     cout << boolalpha << isLeap << endl;
  146.    
  147.     // bad things about FMI
  148.    
  149.     cout << "Velikova nqma da me skusa! " << endl;
  150.     cout << "Bojilov ne e religiq" << endl;
  151.     cout << "Algebrata ne proshtava!" << endl;
  152.    
  153.     // tip point
  154.    
  155.     int x, y, x1, y1, radius;
  156.     cin >> x >> y >> c1 >> c2 >> radius;
  157.    
  158.     bool doesBelong = sqrt(x - x1) * (x - x1) + (y - y1) * (y - y1) <= radius * radius;
  159.    
  160.     cout << boolalpha << doesBelong << endl;
  161.    
  162.     // existing triangle
  163.    
  164.     double a, b, c;
  165.     cin >> a >> b >> c;
  166.    
  167.     bool isProperTriangle = (a + b > c || a + c > b || b + c > a);
  168.     int halfPerimeter = (a + b + c) / 2;
  169.     double area = (sqrt(halfPerimeter(halfPerimeter - a) * (halfPerimeter - b) * (halfPerimeter - c)));
  170.     double perimeter = a + b + c;
  171.    
  172.     cout << boolalpha << isProperTriangle << endl;
  173.     cout << area << endl;
  174.     cout << perimeter << endl;
  175.    
  176.     // determine sum, difference, product and division
  177.    
  178.     int a, b;
  179.     cin >> a >> b;
  180.    
  181.     cout << "Sum of two numbers is: " << a + b << endl;
  182.     cout << "Difference of two numbers is: " << a - b << endl;
  183.     cout << "Multiplication of two numbers is: " << a * b << endl;
  184.     cout << "Division of two numbers is: " << a / b << endl;
  185.    
  186.     // print all the digits of one numbers
  187.    
  188.     int n, sum = 0;
  189.     cout << "Enter a 4-digit number: " << endl;
  190.     cin >> n;
  191.    
  192.     int firstdigit = n / 1000;
  193.     int seconddigit = (n / 100) % 10;
  194.     int thirddigit = (n / 10) % 10;
  195.     int forthdigit = n % 10;
  196.    
  197.     cout << "First digit: " << firstdigit << endl;
  198.     cout << "Second digit: " << seconddigit << endl;
  199.     cout << "Third digit: " << thirddigit << endl;
  200.     cout << "Forth digit: " << forthdigit << endl;
  201.    
  202.     sum = firstdigit + seconddigit + thirddigit + forthdigit;
  203.  
  204.     cout << "The sum of digits: " << sum << endl;
  205.    
  206.     int reverse;
  207.    
  208.     reverse = (forthdigit * 1000) + (thirddigit * 100) + (seconddigit * 10) + firstdigit;
  209.    
  210.     cout << "Reverse number of original number is: " << reverse << endl;
  211.    
  212.     int a,b;
  213.     cout << "Enter two numbers: " << endl;
  214.     cin >> a >> b;
  215.    
  216.     int product = a * b;
  217.    
  218.     cout << product << endl;
  219.     cout << "LastDigit: " << product % 10 << endl;
  220.     cout << "Even or Odd? " << ((product % 10) % 2 == 0) << endl;
  221.    
  222.    
  223.     int a, b;
  224.     cin >> a >> b;
  225.    
  226.     cout << "Before Swapping: " << endl;
  227.     cout << "First: " << a << "\n" << "Second: " << b << endl;
  228.    
  229.     a = a + b;
  230.     b = a - b;
  231.     a = a - b;
  232.    
  233.     // there is a second way
  234.    
  235.     int temp = a;
  236.     a = b;
  237.     b = temp;
  238.    
  239.     cout << "After swapping: " << endl;
  240.     cout << "First: " << a << "\n" << "Second: " << b << endl;
  241.    
  242.    
  243.     // divisor to other one
  244.    
  245.     int a, b;
  246.     cout << "Enter two numbers: " << endl;
  247.     cin >> a >> b;
  248.    
  249.     bool isDivisor = (a % b == 0);
  250.    
  251.     cout << boolalpha << "num1 = " << a << " and " << "num2 = " << b << " => " << isDivisor << endl;
  252.    
  253.    
  254.     double a, b, c;
  255.     cin >> a >> b >> c;
  256.    
  257.     bool isProperTriangle = (a + b > c && a + c > b && b + c > a);
  258.    
  259.     cout << boolalpha << isProperTriangle << endl;
  260.  
  261.     // determine max and min between three numbers
  262.        
  263.     double a, b, c;
  264.     cin >> a >> b >> c;
  265.    
  266.     double max = a;
  267.     double min = a;
  268.    
  269.     if(b > max){
  270.         max = b;
  271.     }
  272.     if(c > max){
  273.         max = c;
  274.     }
  275.     if(b < min){
  276.         min = b;
  277.     }
  278.     if(c < min){
  279.         min = c;
  280.     }
  281.    
  282.     cout << "MAX: " << max << endl;
  283.     cout << "MIN: " << min << endl;
  284.    
  285.     // determine if the number belong to interval
  286.    
  287.     int startInterval, endInterval;
  288.     int x;
  289.     cin >> x;
  290.     cin >> startInterval >> endInterval;
  291.    
  292.     bool isInInterval = (x >= startInterval && x <= endInterval);
  293.    
  294.     cout << boolalpha << isInInterval << endl;
  295.  
  296.    
  297.     // check if year is Leap
  298.    
  299.     int year;
  300.     cin >> year;
  301.    
  302.     bool isLeap = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
  303.    
  304.     cout << boolalpha << isLeap << endl;
  305.    
  306.    
  307.     // building a calculator
  308.    
  309.     int num1, num2;
  310.     char choice;
  311.    
  312.     cout << "Enter first number: " << endl;
  313.     cin >> num1;
  314.    
  315.     cout << "Enter second number: " << endl;
  316.     cin >> num2;
  317.    
  318.     cout << "Enter a choice: " << endl;
  319.     cin >> choice;
  320.    
  321.     switch(choice){
  322.     case '+':
  323.         cout << num1 << " + " << num2 << " = " << num1 + num2;
  324.         break;
  325.     case '-':
  326.         cout << num1 << " - " << num2 << " = " << num1 - num2;
  327.         break;
  328.     case '*':
  329.         cout << num1 << " * " << num2 << " = " << num1 * num2;
  330.         break;
  331.     case '/':
  332.         if(num2 != 0){
  333.             cout << num1 << " / " << num2 << " = " << num1 / num2;
  334.         } else {
  335.             break;
  336.         }
  337.     default:
  338.         cout << "Invalid choice!" << endl;
  339.         break;
  340.     }
  341.    
  342.    
  343.     char character;
  344.    
  345.     if(character >= 'a' && character <= 'z'){
  346.         cout << "The lower case is corresponding to... " << (char) - 32;
  347.     } else if(characer >= 'A' && character <= 'Z'){
  348.         cout << "The upper case is correspoding to... " << (char) + 32;
  349.     } else {
  350.         cout << "Is not a letter!" << endl;
  351.     }
  352.    
  353.     char character;
  354.     cin >> character;
  355.    
  356.     if(character >= '0' && character <= '9'){
  357.         cout << "it's a digit!" << endl;
  358.     } else if(character >= 'a' && character <= 'z'){
  359.         cout << "It's lowercase! " << endl;
  360.     } else if(character >= 'A' && character <= 'Z'){
  361.         cout << "It's uppercase! " << endl;
  362.     } else {
  363.         cout << "Is a special symbol! " << endl;
  364.     }
  365.    
  366.     int month;
  367.     cin >> month;
  368.    
  369.     switch(month){
  370.     case 12:
  371.     case 1:
  372.     case 2:
  373.         cout << "Winter " << endl;
  374.         break;
  375.     case 3:
  376.     case 4:
  377.     case 5:
  378.         cout << "Spring" << endl;
  379.         break;
  380.     case 6:
  381.     case 7:
  382.     case 8:
  383.         cout << "Summer " << endl;
  384.         break;
  385.     case 9:
  386.     case 10:
  387.     case 11:
  388.         cout << "Autumn " << endl;
  389.         break;
  390.     default:
  391.         cout << "Invalid month! " << endl;
  392.         break;
  393.     }
  394.    
  395.    
  396.     int year, month;
  397.    
  398.     cout << "Enter year: " << endl;
  399.     cin >> year;
  400.    
  401.     cout << "Enter month: " << endl;
  402.     cin >> month;
  403.    
  404.     bool isLeap = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
  405.    
  406.     switch(month){
  407.     case 1:
  408.     case 3:
  409.     case 5:
  410.     case 7:
  411.     case 8:
  412.     case 10:
  413.     case 12:
  414.         cout << 31 << endl;
  415.         break;
  416.     case 4:
  417.     case 6:
  418.     case 9:
  419.     case 11:
  420.         cout << 30 << endl;
  421.         break;
  422.     case 2:
  423.         cout << isLeap + 28 << endl;
  424.         break;
  425.     default:
  426.         cout << "Invalid month " << endl;
  427.         break;
  428.     }
  429.    
  430.     int n;
  431.     cout << "Enter a 4-digit number: " << endl;
  432.     cin >> n;
  433.    
  434.     if(n < 999 && n > 10000){
  435.         cout << "You'll get the error!" << endl;
  436.     } else {
  437.         int firstdigit = n / 1000;
  438.         int seconddigit = (n / 100) % 10;
  439.         int thirddigit = (n / 10) % 10;
  440.         int forthdigit = n % 10;
  441.        
  442.         int max = firstdigit;
  443.        
  444.         if(seconddigit > max){
  445.             max = seconddigit;
  446.         } else if(thirddigit > max){
  447.             max = thirddigit;
  448.         } else if(forthdigit > max){
  449.             max = forthdigit;
  450.         }
  451.        
  452.         cout << "Is the first digit even or odd? " << (firstdigit % 2 == 0)
  453.              << "Is the first digit the biggest? " << (firstdigit == max) << endl;
  454.     }
  455.    
  456.     int tomato, patoto, pepper, carrot, olive, flavours;
  457.     bool hasFriend;
  458.    
  459.     cout << "Tomato: " << endl;
  460.     cin >> tomato;
  461.     cout << "Patoto: " << endl;
  462.     cin >> patoto;
  463.     cout  << "Pepper: " << endl;
  464.     cin >> pepper;
  465.     cout << "Carrot: " << endl;
  466.     cin >> carrot;
  467.     cout << "Olive: " << endl;
  468.     cin >> olive;
  469.     cout << "Flavours: " << endl;
  470.     cin >> flavours;
  471.     cout << "Is there a friend? " << endl;
  472.     cin >> hasFriend;
  473.    
  474.     bool studentSalad = (tomato <= '1' || patoto <= '2' || pepper <= '4' || carrot <= '3' || olive <= '3' || flavours <= '150');
  475.     bool studentSoup = (tomato <= '2' || patoto <= '3' || pepper <= '5' || carrot <= '6' || olive <= '10' || flavours <= '200');
  476.     bool studentGuvech = (tomato <= '5' || patoto <= '6' || pepper <= '12' || carrot <= '7' || olive <= '12' || flavours <= '300');
  477.    
  478.     bool isGoingToBeFeed = studentSalad || ((studentSoup || studentGuvech) && hasFriend);
  479.     cout << (isGoingToBeFeed ? "Yes" : "No") << endl;
  480.    
  481.    
  482.     return 0;
  483.    
  484. }
Advertisement
Add Comment
Please, Sign In to add comment