In: Computer Science
"Create a program that displays a table consisting of four rows and five columns. The first column should display the numbers 1 through 4. The second and sub-sequent columns should display the result of multiplying the number in the first column by the numbers 2 through 5. If necessary, create a new project named Introductory14 Project, and save it in the Cpp8\Chap08 folder. Enter the C++ instructions into a source file named Introductory14.cpp. Also enter appropriate comments and any additional instructions required by the compiler. Save and then run the program."
I need help with making this C++ code. it needs to be done using a POST-TEST loop and i am not sure how to use "do" and "while"
code in c++ (code to copy)
#include<bits/stdc++.h>
using namespace std;
int main()
{
// create a table consisting of four rows and five columns
int table[4][5];
// The first column should display the numbers 1 through 4
int i=0;
while(i<4){
table[i++][0]=i;
}
// The second and sub-sequent columns should display
// the result of multiplying the number in the first
// column by the numbers 2 through 5
int col=1;
// using a post test loop
while(1){
//break from loop of column value is 5
if(col==5){
break;
}
int row=0;
// using a post test loop
while(1){
//break from loop of row value is 4
if(row==4){
break;
}
// result of multiplying the number in the first column by the numbers 2 through 5
table[row][col]=table[row][0]*(col+1);
row++;
}
col++;
}
//print the table
for(int i=0;i<4;i++){
for(int j=0;j<5;j++){
cout<<table[i][j]<<" ";
}
cout<<endl;
}
}
Code screenshot
Sample console output screenshot