How do i print the following number pattern(Triangular pattern)

............1
.........1 2 1
......1 2 3 2 1
...1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1

Recommended Answers

All 3 Replies

#include<iostream>

int main(){
    std::cout << "........1\n......1 2 1\n....1 2 3 2 1\n..1 2 3 4 3 2 1\n1 2 3 4 5 4 3 2 1";
}

or you could try something with loops.

But seriously: You should start by writing these problems on paper. Then step by step write down what your program needs to do. If you've written down some ideas, come back here and we'll give advice.

Is the numbers of lines to be printed a fixed number?

#include<iostream>

int main(){
    std::cout << "........1\n......1 2 1\n....1 2 3 2 1\n..1 2 3 4 3 2 1\n1 2 3 4 5 4 3 2 1";
}

or you could try something with loops.

But seriously: You should start by writing these problems on paper. Then step by step write down what your program needs to do. If you've written down some ideas, come back here and we'll give advice.

Is the numbers of lines to be printed a fixed number?

yes

You might want to try a more general approach, where the user
gets to input the number of rows for the tree.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.