Advertisement
MeehoweCK

Untitled

Dec 20th, 2023
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. /*  operatory matematyczne:
  6. +   dodawanie
  7. -   odejmowanie
  8. *   mnożenie
  9. /   dzielenie
  10. %   reszta z dzielenia (modulo)
  11. */
  12.  
  13. int main() {
  14.     int liczba1{ 10 }, liczba2{ 3 };    // inicjalizacja dwóch zmiennych tego samego typu może się odbywać w jednym wierszu, po przecinku
  15.     cout << liczba1 << " + " << liczba2 << " = " << liczba1 + liczba2 << endl;
  16.     cout << liczba1 << " - " << liczba2 << " = " << liczba1 - liczba2 << endl;
  17.     cout << liczba1 << " * " << liczba2 << " = " << liczba1 * liczba2 << endl;
  18.     cout << liczba1 << " / " << liczba2 << " = " << liczba1 / liczba2 << endl;
  19.     // uwaga: dzielenie przez siebie dwóch liczb całkowitych (typ int) zawsze daje wynik całkowity
  20.     cout << liczba1 << " / " << liczba2 << " = " << 1.0 * liczba1 / liczba2 << endl;
  21.     // aby wynik był poprawny (uwzględniający miejsca po przecinku), przynajmniej jedna z liczb biorących udział w dzieleniu musi być zmiennoprzecinkowa
  22.     cout << liczba1 << " % " << liczba2 << " = " << liczba1 % liczba2 << endl;
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement