+ 4

How to make half pyramid in c++?

Can anyone tell me the logic behind making of pyramid in c++ whether it's half pyramid or full pyramid

22nd Mar 2021, 9:00 AM
Nitin Bisht
Nitin Bisht - avatar
13 RĂ©ponses
+ 2
Nested loops .
22nd Mar 2021, 9:05 AM
TOLUENE
TOLUENE - avatar
+ 2
Eddy M for(I=0;I<=5;I++) { For(j=0;j<=I;j++) { Cout<<"*"; } Cout<<endl; }
22nd Mar 2021, 2:02 PM
Nitin Bisht
Nitin Bisht - avatar
+ 2
In innerloop you write j<i how is your code still working because 1 is not less than 1 you have to add <= sign I think correct me if I am wrong
24th Mar 2021, 2:54 AM
Nitin Bisht
Nitin Bisht - avatar
+ 1
Eddy M I just want to how inner for loop working what is the use of j++ in second loop
22nd Mar 2021, 2:03 PM
Nitin Bisht
Nitin Bisht - avatar
+ 1
Nitin Bisht j++ counts every "*" on a line until you reach I, the number of the line. You need to declare int I and int j before using them and you probably wanted to write cout, not Cout and for instead of For. I guess your editor did the capitalization.
22nd Mar 2021, 5:10 PM
Eddy M
0
It's a combination of triangle. First triangle is made of " "(empty space...) Then the second one is of * you have to make both the triangles simultaneously
22nd Mar 2021, 9:58 AM
Kashyap Kumar
Kashyap Kumar - avatar
0
Beegcat, I can't figure out the code for half pyramid like in first row there is one star, in 2nd row there is 2 star and in 3rd row there is 3 star and so on to 5th row .
22nd Mar 2021, 10:31 AM
Nitin Bisht
Nitin Bisht - avatar
0
You already noticed in Nth row there are N stars, can you write the code now?
22nd Mar 2021, 1:34 PM
Eddy M
0
Eddy M yes
22nd Mar 2021, 1:59 PM
Nitin Bisht
Nitin Bisht - avatar
0
Nitin Bisht Try replacing: cout<<"*"; with cout<<i; and run it (use I if you still have it like that) then cout<<"*"; with cout<<j; and run it I hope you will understand how i and j work in the codes.
25th Mar 2021, 12:40 AM
Eddy M
- 2
Eddy M do you know html table also?
22nd Mar 2021, 5:14 PM
Nitin Bisht
Nitin Bisht - avatar