Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program that displays a table consisting of four rows and five columns.

ID: 3571344 • Letter: C

Question


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 subsequent 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 Introductory 14 Project, and save it in the Cpp8Chap08 folder. Enter the C++ instructions into a source file named Introductory 14.cpp. Also enter appropriate comments and any additional instructions required by the compiler. Save and then run the program.

Explanation / Answer

#include <iostream>

using namespace std;

int main()
{//2D array to store numbers
int table[4][5];
/* loop to fullfill conditions of array */
for(int i=0;i<4;i++){
for(int j=0;j<5;j++){
//if first coloumn fill from 1 to 4
if(j==0)
table[i][j]=i+1;
//in other coloumns mulriply by 2 3 4 5
else
table[i][j]=table[i][0]*(j+1);
}
}

//printing elements of the final array
for(int i=0;i<4;i++){
  

for(int j=0;j<5;j++)
cout <<table[i][j]<<" ";
cout<<endl;
}
  
return 0;
}

/******OUTPUT*********
1 2 3 4 5   
2 4 6 8 10
3 6 9 12 15   
4 8 12 16 20
*******OUTPUT**********/

/* Note:This code has been tested on g++ compiler,please do ask in case of any doubt,would glad to help you !! */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote