A very basic multiplication table former. It asks you to enter a number, then displays a 5x5 grid-like multiplication table with the base number you entered. It starts from 1. Useful for teaching younger kids their times tables, or people who aren't so good with multiplication.
You can use it from the command line, I would recommend maximizing your screen when using big numbers.
Command line usage:
Windows: ()
Linux: (<filepath)>)./
Note: the grid may break. I could correct it, but as this isn't a big code, it would be pointless. It's legible, that's all that matters.
#include <iostream>
#include <stdlib.h>
using std::cout;
using std::cin;
using std::endl;
int main(int argc, char *argv[])
{
const int rows = 5, cols = 5;
int n, s = 1;
if (argc == 2)
{
char *d;
n = strtol(argv[1],&d,10);
}
else {
cout << "Enter a number: ";
cin >> n;
cout << "\n";
}
for (int i = 1;i <= cols;i++)
{
for (int c = 1; c <= rows;s++)
{
cout << n << " x " << s << " = " << n*s << " \t";
c++;
}
cout << endl;
}
return 0;
}