Here's the result:
How long this table should be ? (0 - 50) 5
| 1 | 2 | 3 | 4 | 5 |
================================================
1 I 1 | 2 | 3 | 4 | 5 |
-------+-------+-------+-------+-------+-------+
2 I 2 | 4 | 6 | 8 | 10 |
-------+-------+-------+-------+-------+-------+
3 I 3 | 6 | 9 | 12 | 15 |
-------+-------+-------+-------+-------+-------+
4 I 4 | 8 | 12 | 16 | 20 |
-------+-------+-------+-------+-------+-------+
5 I 5 | 10 | 15 | 20 | 25 |
-------+-------+-------+-------+-------+-------+
/* Multiplication table */
#include <stdio.h>
short tableSize; // Number of multipliers
short question (short *pointSize); // Ask user how many multipliers
void error(short nbUser); // Cherck error
void multTable(); // The table
void main ()
{
short i = 1, nbMultipliers;
question(&nbMultipliers);
error(&nbMultipliersnbMultipliers);
tableSize = nbMultipliers;
/* header */
printf(" |");
for (i = 1; i <= tableSize; i++)
{
printf(" %3u |", i);
}
printf("\n");
for (i = 1; i <= (tableSize + 1); i++)
{
printf ("========");
}
printf("\n");
/* end header */
multTable(); // the table
}
/* Ask user how many multipliers */
short question (short *pointSize)
{
*pointSize = NULL;
printf("How long this table should be ? (0 - 50) ");
scanf("%u", pointSize);
printf("\n");
}
void error (short nbUser)
{
if (nbUser < 0 || nbUser > 50)
{
printf("Error : you must enter a number between 0 and 50");
}
}
/* end Ask user how many multipliers */
void multTable()
{
short i = 1, j = 1;
short line[50] = {0};
for (j = 1; j <= tableSize; j++)
{
printf(" %3u I", j);
for (i = 1; i <= tableSize; i++)
{
line[i] = i*j;
printf (" %3u |", line[i]);
}
printf("\n");
for (i = 1; i <= (tableSize + 1); i++)
{
printf ("-------+");
}
printf("\n");
}
}