Solved

Pls help to solve this using loops.

Posted on 2004-08-10
3
256 Views
Last Modified: 2012-05-05
hi experts,
i am trying to do this for hours now, still could not figure out how to do this. Please help me, I am new in C.
thanks in advance for the help
I want to write a program to get an output like this: A B C D E F G F E D C B A
                                                                           A B C D E F    F E D C B A
                                                                           A B C D E          E D C B A
                                                                           A B C D                D C B A
                                                                           A B C                       C B A
                                                                           A B                             B A
                                                                           A                                   A


int i,j;
i='G';
clrscr();
while(i>='A')                                   I  wrote this and able to manage the first part , that is  ABCDEFG
  {                                                                                                                                 ABCDEF
  j='A';                                                                                                                           ABCDE
  while(j<=i)                                                                                                                   ABCD
                                                                                                                                     ABC{                                                                                                                                    AB  
                                                                                                                                     A
                                                                                                                                                                     
    printf ("%c",j);
    j++;
    }
    printf ("\n");
   i--;
  }
  getch();
}

but i could not write  code to get the whole ouput, please give me some hints to go furthur ,
thnaks,
Deep.
0
Comment
Question by:deepthiji
  • 2
3 Comments
 
LVL 3

Author Comment

by:deepthiji
ID: 11765507
Important thing i forgot to mention is,i can only use loops, because i reached untill loops >).
so please make sure, use only loops nothing else.
thanks
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 11766085
That code should do what you want

    int min = 'A';
    int max = 'G';
    int j = max;
    int i;

    while (j >= min) {
        i = min;
        while(i < max) {
            if (i <= j) {
                printf("%c", i);
            } else {
                printf(" ");
            }
            ++i;
        }

        while(i >= 'A') {
            if (i <= j) {
                printf("%c", i);
            } else {
                printf(" ");
            }
            --i;
        }
        printf("\n");
        --j;
    }
0
 
LVL 3

Author Comment

by:deepthiji
ID: 11766523

Thanks a lot for the help. i understood now.
Thanks once again.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question