Write a program to find the table of numbers using a while loop. Your program should ask the size of the table. That size defines the rows and columns. Sample output:
IT must be done using WHILE loop.
Enter size: 6
1 2 3 4 5 6
------------------------------------------
1* 1 2 3 4 5 6
2* 2 4 6 8 10 12
3* 3 6 9 12 15 18
4* 4 8 12 16 20 24
5* 5 10 15 20 25 30
6* 6 12 18 24 30 36
#include <iostream>
int main() {
int table_size;
std::cout << "Enter size: ";
std::cin >> table_size;
int i = 1;
while (i <= table_size) {
std::cout << i << ' ';
++i;
}
std::cout << std::endl;
std::cout << "------------------------------------------";
std::cout << std::endl;
int row = 1, col = 1;
while (row <= table_size) {
if (col == 1) {
std::cout << row << "* ";
}
std::cout << row * col << ' ';
if (col == table_size) {
++row;
col = 1;
std::cout << std::endl;
} else {
++col;
}
}
return 0;
}
Comments
Leave a comment