A toy company manufactures electronic learning boards for kids to learn alphabets. Accordingly,
when a kid presses 1 alphabet a is shown on the screen, and when 2 is pressed ab is shown along
with the previous alphabet and so on. The patterns are likely to be as follow:
a
ab
abc
abcd
abcde
:
:
:
:
a
Develop a C-script which generates the above-mentioned pattern.
Note : Don't use array ,just use loops
#include <stdio.h>
int main()
{
int n;
printf("Enter a number: ");
scanf("%d",&n);
if(n==1){
printf("a");
}
else if(n==2){
printf("ab");
}
else if(n==3){
printf("abc");
}
else if(n==4){
printf("abcd");
}
else if(n==5){
printf("abcde");
}
else if(n==6){
printf("abcdef");
}
else if(n==7){
printf("abcdefg");
}
else if(n==8){
printf("abcdefgh");
}
else if(n==9){
printf("abcdefghi");
}
else if(n==10){
printf("abcdefghij");
}
else if(n==11){
printf("abcdefghijk");
}
else if(n==12){
printf("abcdefghijkl");
}
else if(n==13){
printf("abcdefghijklm");
}
else if(n==14){
printf("abcdefghijklmn");
}
else if(n==15){
printf("abcdefghijklmno");
}
else if(n==16){
printf("abcdefghijklmnop");
}
else if(n==17){
printf("abcdefghijklmnopq");
}
else if(n==18){
printf("abcdefghijklmnopqr");
}
else if(n==19){
printf("abcdefghijklmnopqrs");
}
else if(n==20){
printf("abcdefghijklmnopqrst");
}
else if(n==21){
printf("abcdefghijklmnopqrstu");
}
else if(n==22){
printf("abcdefghijklmnopqrstuv");
}
else if(n==23){
printf("abcdefghijklmnopqrstuvw");
}
else if(n==24){
printf("abcdefghijklmnopqrstuvwx");
}
else if(n==25){
printf("abcdefghijklmnopqrstuvwxy");
}
else if(n==26){
printf("abcdefghijklmnopqrstuvwxyz");
}
}
Comments
Leave a comment