Advertisement
alansam

Multiplication table.

Apr 24th, 2022
1,114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <string>
  5.  
  6. int main() {
  7.   std::cout << "print out multiplication table\n";
  8.   std::cout << std::string(80, '-') << '\n';
  9.  
  10.   auto constexpr max { 20u };
  11.   auto val { 0u };
  12.   std::cout << "number from 1 to " << max << ": ";
  13.   std::cin >> val;
  14.   std::cout.put('\n');
  15.   if (val > 0u && val <= 20u) {
  16.     for (auto nr { 1u }; nr <= max; ++nr) {
  17.       std::cout << std::setw(3) << nr
  18.                 << " x"
  19.                 << std::setw(3) << val
  20.                 << " ="
  21.                 << std::setw(4) << nr * val
  22.                 << '\n';
  23.     }
  24.     std::cout << std::endl;
  25.   }
  26.   else {
  27.     std::cout << val << " out of range!\n";
  28.   }
  29.  
  30.   return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement