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
1
Expert's answer
2012-11-05T10:06:30-0500
#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

LATEST TUTORIALS
APPROVED BY CLIENTS