62 556
Assignments Done
98,8%
Successfully Done
In June 2018

Answer to Question #17814 in C++ for Asma

Question #17814
Write a C++ program that reads the number of rows R from the user and displays the shape of a number based triangle using only for loops. If R = 4 the output will be:
1
2 4 6
3 6 9 12 15
4 8 12 16 20 24 28
Expert's answer
#include <iostream>

using namespace std;

void main()
{
intR,s,n=1;
cout<< "Enter the number: ";
cin>> R;
s= (R-1)*2;
for(inti = 1; i <= R; i++)
{
for(intk = 0; k < s; k++)
cout<< " ";
for(intj = 1; j <= n; j++)
cout<< i*j << " ";
n+=2;
s-=2;
cout<< endl;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

32px
07.10.14, 18:47

hi, can you please explain the answer? thank you

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions