Skip to content

Instantly share code, notes, and snippets.

@brijeshb42
Last active August 29, 2015 13:57
Show Gist options
  • Save brijeshb42/9516037 to your computer and use it in GitHub Desktop.
Save brijeshb42/9516037 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
void printPattern(int a,int b){
if(a==0){
return;
}
printPattern(a-1,b+1);
for(int i=1;i<=b;i++){
cout<<' ';
}
for(int i=1;i<=a;i++){
cout<<(char)('A'+i-1);
}for(int i=a-1;i>=1;i--){
cout<<(char)('A'+i-1);
}
for(int i=1;i<=b;i++){
cout<<' ';
}
cout<<endl;
}
int main() {
// your code goes here
//take A=1, B=2, ..... , Z = 26
// If the largest alphabet to be printed is I,
// then use its numerical equivalent I = 9
// and similarly do it for other integers.
int n;
char ch;
cout<<"Enter the largest alphabet present in the pattern: ";
cin>>ch;
if(ch>='a' && ch<='z'){
ch = ch-'a'+'A';
}
printPattern((int)(ch-'A'+1),0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment