answersLogoWhite

0


Best Answer

#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

9y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

#include<conio.h>

#include<stdio.h>

main()

{

int n,i,j;

printf("\n ntr n value");

scanf("%d",&n);

for(i=1;i<=n;i++)

{

for(j=1;j<=i;j++)

{

printf("%d",j);

}

printf("\n");

}

getch();

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you print a pyramid of numbers C plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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 c program to print the following pyramid 1 121 1231 12321 1234321?

123454321


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);