Last active
August 29, 2015 13:57
-
-
Save brijeshb42/9516037 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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