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 14
#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 and end \n";
cin>>a>>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)i;
}
cout<<"\n";
}
getch();
}
The code given below can be used for g++/gcc Compiler:-
//pattern 14
#include<iostream>
using namespace std;
int main()
{
int n,i,j;
char a;
char b;
cout<<"Enter the alphabet from where to start and end \n";
cin>>a>>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)i;
}
cout<<"\n";
}
return 0;
}
#ENJOY CODING
Â
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP