Advertisement
avr39ripe

cpp%Basics

Jan 11th, 2022
1,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.  
  6.     int firstNum{10};
  7.     int secondNum{3};
  8.     int result{0};
  9.     int reminder{ 0 };
  10.  
  11.     //std::cout << "Enter a ";
  12.     //std::cin >> a;
  13.  
  14.     //std::cout << "Enter b ";
  15.     //std::cin >> b;
  16.  
  17.     result = firstNum / secondNum;
  18.     reminder = firstNum - ((firstNum / secondNum ) * secondNum);
  19.     reminder = firstNum % secondNum;
  20.  
  21.     //10
  22.  
  23.     // 10 / 2 = 5
  24.     //
  25.     // 1 2 -> 1 / 2 = 0 -> 1 - (1 / 2) * 2 -> 1 - 0 * 2 -> 1 - 0 -> 1
  26.     //
  27.     // 0 % 2 = 0
  28.     // 1 % 2 = 1
  29.     // 2 % 2 = 0
  30.     // 3 % 2 = 1
  31.     // 4 % 2 = 0
  32.     //
  33.     // ...
  34.     // 10 % 2 = 0
  35.     // 11 % 2 = 1
  36.     // 12 % 2 = 0
  37.     // 13 % 2 = 1
  38.  
  39.     // 0 % 3 = 0
  40.     // 1 % 3 = 1
  41.     // 2 % 3 = 2
  42.     // 3 % 3 = 0
  43.     // 4 % 3 = 1
  44.     // 5 % 3 = 2
  45.     // 6 % 3 = 0
  46.     // 7 % 3 = 1
  47.     // 8 % 3 = 2
  48.     // 9 % 3 = 0
  49.  
  50.  
  51.     // n % m -> [0 .. m - 1]
  52.  
  53.     std::cout << "firstNum divided by secondNum is " << result << '\n';
  54.     std::cout << "reminder from firstNum divided by secondNum is " << reminder << '\n';
  55.    
  56.  
  57.  
  58.     return 0;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement