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
Program to print ‘N’ alphabet using the number pattern from 1 to n in C++
In this tutorial, we will be discussing a program to print ‘N’ alphabet using the number pattern from 1 to n.
For this we will have to print the english alphabet N. Our task is to determine the size of the letter and print it back using the numbers from 1 to n.
Example
#include <iostream>
using namespace std;
//printing the letter N
void print_N(int N){
int index, side_index, size;
int Right = 1, Left = 1, Diagonal = 2;
for (index = 0; index < N; index++) {
cout << Left++;
for (side_index = 0; side_index < 2 * (index);
side_index++)
cout << " ";
if (index != 0 && index != N - 1)
cout << Diagonal++;
else
cout << " ";
for (side_index = 0; side_index < 2 * (N - index - 1);
side_index++)
cout << " ";
cout << Right++;
cout << endl;
}
}
int main(int argc, char** argv){
int Size = 8;
print_N(Size);
return 0;
}
Output
1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8
Advertisements