Displays the product table for N varying from 1 to 10:
X*Y I 0 1 2 3 4 5 6 7 8 9 10 -------------------------------------------------- 0 I 0 0 0 0 0 0 0 0 0 0 0 1 I 0 1 2 3 4 5 6 7 8 9 10 2 I 0 2 4 6 8 10 12 14 16 18 20 3 I 0 3 6 9 12 15 18 21 24 27 30 4 I 0 4 8 12 16 20 24 28 32 36 40 5 I 0 5 10 15 20 25 30 35 40 45 50 6 I 0 6 12 18 24 30 36 42 48 54 60 7 I 0 7 14 21 28 35 42 49 56 63 70 8 I 0 8 16 24 32 40 48 56 64 72 80 9 I 0 9 18 27 36 45 54 63 72 81 90 10 I 0 10 20 30 40 50 60 70 80 90 100
Difficulty level
Video recording
This exercise is mostly suitable for students
#include <stdio.h>
#include <conio.h>
void main()
{
const int MAX = 10; /* number of lines and columns */
int I, J;
/* Display the header */
printf(" X*Y I");
for (J=0 ; J<=MAX ; J++)
printf("%4d", J);
printf("\n");
printf("------");
for (J=0 ; J<=MAX ; J++)
printf("----");
printf("\n");
/* Display the table */
for (I=0 ; I<=MAX ; I++)
{
printf("%3d I", I);
for (J=0 ; J<=MAX ; J++)
printf("%4d", I*J);
printf("\n");
}
getch();
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Width of binary trees - iterative version