Answer to Question #264761 in C for Jack

Question #264761

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.

1
Expert's answer
2021-11-12T00:09:16-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS