Thread: Output from nested loops

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    3

    Question Output from nested loops

    Hello, I,m trying to get this output from some nested loops, which is becoming very frustrating. So far this is what i have.
    Entering D:
    A
    AB
    ABC
    ABCD
    whereas i need the following type of output:

    A
    ABA
    ABCBA
    ABCDCBA
    ABCDEDCBA

    Except not like this but in pyramid shape.
    I've been at this for hours but can't figure it out-any help would be much appreciated!!

    #include <stdio.h>
    #include <ctype.h>
    int main(void)
    {
    int x,y;
    char ch,in;

    printf("Get a Capital character: ");
    scanf("%c",&in);

    for (x = 'a'; x <= in; x++)
    {
    for (ch = 'a';ch <= x;ch++)
    printf("%c",toupper(ch));
    printf("\n");

    }
    return 0;
    }

  2. #2
    ams80
    Guest
    #include <stdio.h>
    #include <ctype.h>
    int main(void)
    {
    int p,q,x,y;
    char ch,in;
    printf("\nEnter a lower case letter:\n\n");
    fflush(stdout);
    printf("\nGet a Capital character: \n\n");
    scanf("%c",&in);
    p=in-'a'+1; /* position in alphabet of in i.e. a=1,b=2,c=3... */
    for(x='a',q=p;x<=in;x++)
    {
    for(y=1;y<q;y++) printf(" "); /* inserts the relevant amount of spaces*/
    for(ch='a';ch<=x;ch++) printf("%c",toupper(ch));
    for(ch=x-1;ch>='a';ch--) printf("%c",toupper(ch));
    printf("\n");
    q--;
    }
    return 0;
    }

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    3

    Smile

    ams80 thanks for your help!! i really do appreciate your help
    greatly.
    Izaak

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem in Nested Loops
    By umair_crash in forum C++ Programming
    Replies: 12
    Last Post: 09-16-2008, 08:35 AM
  2. Need help, nested loops
    By engstudent363 in forum C Programming
    Replies: 2
    Last Post: 02-17-2008, 10:23 PM
  3. Nested Loops: Confusion
    By chubbs1900 in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2007, 08:04 PM
  4. nested For loops
    By Chaplin27 in forum C++ Programming
    Replies: 1
    Last Post: 03-09-2005, 10:12 AM
  5. Nested For Loops
    By smitsky in forum C++ Programming
    Replies: 2
    Last Post: 11-28-2004, 01:58 PM