Program to print ‘N’ alphabet using the number pattern from 1 to n in C++

C++Server Side ProgrammingProgramming

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

 Live Demo

#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
raja
Published on 19-Dec-2019 10:12:42
Advertisements