Advertisement
andrewb

array_loops.cpp

May 13th, 2014
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>;
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     // This is the table to hold the multiplication tables
  8.     int mults[10][10];
  9.  
  10.     // These variables manipulate the loops
  11.     int x = 0, y = 0, start = 0, max = 10;
  12.  
  13.     // These find a number from the table
  14.     int a, b;
  15.  
  16.     // An initial statment
  17.     cout << "Building multiplication table..." << endl;
  18.  
  19.     // Loop #1
  20.     while (y < max)
  21.     {
  22.         // Reset x to zero
  23.         x = start;
  24.  
  25.         // Loop #2
  26.         while (x < max)
  27.         {
  28.             // Ass a product to the array
  29.             mults[y][x] = y * x;
  30.  
  31.             // Increment x by one
  32.             x++;
  33.         }
  34.  
  35.         // Increment y by one
  36.         y++;
  37.     }
  38.  
  39.     // Access the table
  40.     cout << "Enter a number between 0-9: ";
  41.     cin >> a;
  42.     cout << "Enter another: ";
  43.     cin >> b;
  44.     cout << a << " * " << b << " = " << mults[a][b] << endl;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement