In: Computer Science
needs to be done in C++
Q6. Coding Question (you must code this problem and submit via Blackboard):
Keep everything as Integers.
Row and Column Numbering starts at 1.
Equation for each Cell : Coll = (Row * Col * 10)
Using Nested Loops display the following exactly as it is shown below:
Columns %
Brand 1 2 3 4
A 10 20 30 40
B 20 40 60 80
C 30 60 90 120
D 40 80 120 160
#include <iostream>
using namespace std;
int main()
{
int Col,Row,Coll,n=5;
cout<<"\t\tColumns%"<<endl; //To display Columns%
cout<<"Brand\t"; //display Brand
for(Row=1;Row<=n;Row++)
cout<<Row<<"\t"; //To print 1,2...4 in 2nd row
cout<<endl;
for(Row=1;Row<=n;Row++) //Row value varies from 1 to 4
{
cout<<char('A'+(Row-1))<<"\t"; //To display A,B,C,D.
//ascii value of A is added to (Row-1) and converts to char.
for(Col=1;Col<=n;Col++) //Col value varies from 1 to 4
{
Coll=(Row * Col * 10); //calculate cell value using given formuala
cout<<Coll<<"\t";
}
cout<<endl;
}
return 0;
}
Working of nested loop, n=4
for(Row=1;Row<=n;Row++) //Row value varies from 1 to 4
{ for(Col=1;Col<=n;Col++) //Col value varies from 1 to 4
{
Coll=(Row * Col * 10); //calculate cell value using given formuala
}
}
Row=1
ROW |
1 |
1 |
1 |
1 |
COLUMN |
1 |
2 |
3 |
4 |
CELL VALUE |
1*1*10=10 |
1*2*10=20 |
1*3*10=30 |
1*4*10=40 |
ROW=2
ROW |
2 |
2 |
2 |
2 |
COLUMN |
1 |
2 |
3 |
4 |
CELL VALUE |
2*1*10=20 |
2*2*10=40 |
2*3*10=60 |
2*4*10=80 |
ROW=3
ROW |
3 |
3 |
3 |
3 |
COLUMN |
1 |
2 |
3 |
4 |
CELL VALUE |
3*1*10=30 |
3*2*10=60 |
3*3*10=90 |
3*4*10=120 |
ROW=4
ROW |
4 |
4 |
4 |
4 |
COLUMN |
1 |
2 |
3 |
4 |
CELL VALUE |
4*1*10=40 |
4*2*10=80 |
4*3*10=120 |
4*4*10=160 |