Create a program that displays a table consisting of four rows and five columns.
ID: 3571344 • Letter: C
Question
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 !! */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.