Solved

Pls help to solve this using loops.

Posted on 2004-08-10
3
253 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now