I\'m so lost.. could anyone please help me with this intro to C++ homework probl
ID: 3845993 • Letter: I
Question
I'm so lost.. could anyone please help me with this intro to C++ homework problem?
Explanation / Answer
#include <iostream>
using namespace std;
int main() {
// As this is introduction to C++
// I guess this program is introduction to for loop.
// steps:
// 1) Declare array to store values
// we need to store following matrix as indicated in questions
//1 2 3 4 5
//2 4 6 8 10
//3 6 9 12 15
//4 8 12 16 20
// 2) Print using for loop
//Step 1: declare integer 2 Dimentional array
int arr[4][5]={{1,2,3,4,5},{2,4,6,8,10},{3,6,9,12,15},{4,8,12,16,20}};
// Step 2: Print array using for loop
for(int i=0;i< 4 /*Number of rows */;i ++)
{
for(int j=0;j<5 /*Number of columns*/;j++)
{
cout<<arr[i][j];
cout<<" "; //add space between 2 number
}
cout<<" ";
}
return 0;
}
Output:
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
Dear friend,
I have added required comments in code itself. Hope this will help you.