i need help with creating a letter pyramid usin c.
this is what the basic pyramid should look like.
the - are spaces in front of the letters.

example 1
Type a single lowercase letter and press enter: 3
That is not a letter, enter a lowercase letter:=
That is not a letter, enter a lowercase letter:!
That is not a letter, enter a lowercase letter:e
----A
---ABA
--ABCBA
-ABCDCBA
ABCDEDCBA

example 2
Type a single lowercase letter and press enter: p
---------------A
--------------ABA
-------------ABCBA
------------ABCDCBA
-----------ABCDEDCBA
----------ABCDEFEDCBA
---------ABCDEFGFEDCBA
--------ABCDEFGHGFEDCBA
-------ABCDEFGHIHGFEDCBA
------ABCDEFGHIJIHGFEDCBA
-----ABCDEFGHIJKJIHGFEDCBA
----ABCDEFGHIJKLKJIHGFEDCBA
---ABCDEFGHIJKLMLKJIHGFEDCBA
--ABCDEFGHIJKLMNMLKJIHGFEDCBA
-ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA

Recommended Answers

All 10 Replies

Member Avatar for iamthwee

i need help with creating a letter pyramid usin c.
this is what the basic pyramid should look like.
example 1
Type a single lowercase letter and press enter: 3
That is not a letter, enter a lowercase letter:=
That is not a letter, enter a lowercase letter:!
That is not a letter, enter a lowercase letter:e
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA

example 2
Type a single lowercase letter and press enter: p
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA

Great, what does your flow chart look like?

@dc87

Please post what you have written so far ( your C code ) so we can help you out with the problems you are facing. Please dont expect a readymade answer.

im kind of a beginner at this and my teacher expects a lot from us so i have sarted something but im having trouble printing the letters lets say the user types in p i can conver the small p toa capital p but i can get it to print like
A
B
C
D all the way to p

#include <stdio.h>
    // continue.c

int main(void)
{
    char letter;
        int rows;
    char spaces;
    spaces=' ';
    

    printf("Type a single lowercase letter and press enter:");
    scanf("%c",&letter);
        if((letter<96) || (letter>122));
        {
            printf("That is not a lowercase letter enter a lowercase letter");
            
        }
        else
        {
            letter=letter-32;
            for(letter='A'; letter<96 || letter>122; letter++)
            {

            for(spaces=0; spaces < 0; spaces++);    
            {
                spaces=letter-1;
                putchar(spaces);
                spaces++;
            }

            for(rows=0; rows < 0; rows++)
            {
                rows=letter-'A';
                putchar(rows);
                rows++;
            }
        }
    
    return 0;
}

i also know that using the spaces are generated by the letter-a. lets say the user types in letter e the ascii value is 101 - letter a which is accii value 97 that would create the number of spaces which is 4

else
    {
        letter=letter-32;
        for(letter='A'; letter<96 || letter>122; letter++)
        {

Your for statement just destroyed the letter you typed in.

Also, it would be better to use getchar() instead of scanf() to read in a character. getchar() is designed to read a char whereas scanf() has to process the "%c" to find out you want to read a character then do what getchar() already does.

ok thx but how can i get the letters to print downwards now?

printf("\n"); ?

the following written attachment can be your answer....

Stop attaching short programs, please. It's better to embed the code in your post when you can and attach only when the code is far too long to be put in a post.

the following written attachment can be your answer....

Make a habit of noticing the date when the post was written, and then make a judgment if your comment is going to be of some value, based on the time passed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.