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.
#include <stdio.h>
int main() {
char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
int n = sizeof(alphabet) / sizeof(alphabet[0]) - 1;
char ch;
for (int i=0; i<n; i++) {
ch = getc(stdin);
for (int j=0; j<=i; j++) {
for (int k=0; k<=j; k++) {
fputc(alphabet[k], stdout);
}
fputc('\n', stdout);
}
fputc('\n', stdout);
}
return 0;
}
Comments
Leave a comment