
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print Pattern of Numbers in C++
In this tutorial, we will be discussing a program to print a given pattern of numbers.
Our task is to make use of looping structure in the code and print the given pattern −
1 232 34543 4567654 567898765
Example
#include<bits/stdc++.h> using namespace std; int main(){ int n = 5, i, j, num = 1, gap; gap = n - 1; for ( j = 1 ; j <= n ; j++ ){ num = j; for ( i = 1 ; i <= gap ; i++ ) cout << " "; gap --; for ( i = 1 ; i <= j ; i++ ){ cout << num; num++; } num--; num--; for ( i = 1 ; i < j ; i++){ cout << num; num--; } cout << "\n"; } return 0; }
Output
1 232 34543 4567654 567898765
Advertisements