0
Building a pyramid in C++
How do i build a pyramid, given number of blocks.?
4 Réponses
+ 2
U need to learn about conditionals statement loops and basic knowledge of matrix refer any tutorials it might be helpful for you
+ 1
You can post here also no problem this forum is created for your problems feel free to ask doubts
0
Please can i DM you?
I'll show you my attempt
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.