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
:
:
:
:
abcdefghijklmnopqrstuvwxyz
Develop a C-script which generates the above-mentioned pattern
Note: Don't use array , do with loops
Source code
#include <stdio.h>
int main()
{
char alphabet[26]="abcdefghijklmnopqrstuvwxyz";
int n;
printf("\nEnter a number: ");
scanf("%d",&n);
for(int i=0;i<n;i++){
for(int j=0;j<=i;j++){
printf("%c",alphabet[j]);
}
printf("\n");
}
return 0;
}
Output
Comments
Leave a comment