answersLogoWhite

0

#include<iostream>

#include<vector>

#include<string>

#include<random>

#include<ctime>

void print_pyramid (const std::vector<int>& v)

{

size_t tiers {v.size()}, spaces {1}, row {1};

while (tiers > row)

{

tiers -= row++;

++spaces;

}

tiers = spaces + 1;

std::vector<int>::const_iterator i=v.begin();

for (size_t tier=0; tier!=tiers; ++tier)

{

if (spaces)

std::cout << std::string(spaces--,'\t');

for (size_t num=0; num!=tier && i!=v.end(); ++num)

std::cout << *i++ << "\t\t";

std::cout << std::endl;

}

}

int main()

{

std::default_random_engine generator ((unsigned)time(0));

std::uniform_int_distribution<int> distribution (1,100);

for (size_t loop=0; loop!=5; ++loop)

{

size_t max = distribution (generator);

std::vector<int> v;

v.reserve (max);

for (size_t i=0; i!=max; ++i)

v.push_back (distribution (generator));

print_pyramid (v);

}

}

User Avatar

Wiki User

10y ago

What else can I help you with?

Related Questions

C program to print numbers 1 to n?

how do we use loops in c plus plus programing and what are basic differences between do,for and while loop


What is the use of print option in c plus plus?

C++ has no print option. The print option in your IDE allows you to print your C++ source code, thus giving you a "hard" copy of your code.


How do you print to the screen in C plus plus?

printf();


C plus plus program to print number patterns?

bghjg


Do I need a C plus plus program to print PASCAL's triangle?

No.


Write a C plus plus function that print a triangle of stars?

Write a function that print a triangle of stars.


How print the string with double cot in c plus plus language?

console.wrikerle("""");


Write a program to print odd numbers In C plus plus between 51 to 100?

#include &lt;iostream&gt; int main() { for(int i=51; i &lt;= 100; i+=2) { cout &lt;&lt; i &lt;&lt; endl; } return 0; }


How do you write a C plus plus program that displays a pyramid of Xes on the screen using a for loop?

printf ("x")


How do you add more than two numbers in C plus plus?

sum = a + b + c;


Write a c or c plus plus program to print first 50 odd numbers using do while loop?

unsigned count = 0;unsigned num=1; do { std::cout &lt;&lt; num &lt;&lt; std::endl; num +=2; } while (++count&lt;50);


How can you print your name in c or c plus plus with out using semi column?

You can not print your name in C without a semi colon because according to the rules of C every statement should end with a semi colon.In fact without the semi colon it fails to be a valid C statement.