Rectangle pattern || alphabets || patterns || for loop || C++
In this, we are going to see how to print the above pattern of Alphabets, using nested for loops in C++.


The code given below can be used for TURBO C++ Compiler:-

// pattern 15
#include<iostream.h>
#include<conio.h>
void main()
{
  clrscr();
  int n,i,j;
  char a;
  char b;
  cout<<"Enter the alphabet from where to start\n";
  cin>>a;
  cout<<"Enter the alphabet till where to End\n";
  cin>>b;
  for(i=a;i<=b;i++)
  {
    for(j=a;j<=b;j++)
    {

      // (char)-this keyword convert the ASCII value to the Alphabets.
      cout<<(char)j;
    }
    cout<<"\n";
  }
  getch();
}
  
    

The code given below can be used for g++/gcc Compiler:-

// pattern 15
#include<iostream>
using namespace std;
int main()
{
  int n,i,j;
  char a;
  char b;
  cout<<"Enter the alphabet from where to start\n";
  cin>>a;
  cout<<"Enter the alphabet till where to End\n";
  cin>>b;
  for(i=a;i<=b;i++)
  {
    for(j=a;j<=b;j++)
    {

      // (char)-this keyword convert the ASCII value to the Alphabets.
      cout<<(char)j;
    }
    cout<<"\n";
  }
  return 0;
}
  
    
#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post