Building a pyramid in C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Building a pyramid in C++

How do i build a pyramid, given number of blocks.?

1st Nov 2021, 9:29 AM
Winner!
Winner! - avatar
4 Answers
+ 2
U need to learn about conditionals statement loops and basic knowledge of matrix refer any tutorials it might be helpful for you
1st Nov 2021, 9:34 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
You can post here also no problem this forum is created for your problems feel free to ask doubts
1st Nov 2021, 9:42 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Please can i DM you? I'll show you my attempt
1st Nov 2021, 9:40 AM
Winner!
Winner! - avatar
0
My attempt from the internet and other resources: #include <iostream> using namespace std; void pyramid(int num){ for(int i = 1;i <= num;i++){ for(int j = i;j <= num;j++){ cout << " "; } for(int a = 1;a <= 2 * i - 1;a++){ cout << "*"; } cout << endl; } } int main(){ pyramid(5); return 0; } Problem: This builds the pyramid based on rows What I want is to build the pyramid given number of blocks. Example: given 9 blocks output; * *** ***** Example: given 17 blocks Output: * *** ***** ******* 1 block left.
1st Nov 2021, 9:54 AM
Winner!
Winner! - avatar