Solved

Pls help to solve this using loops.

Posted on 2004-08-10
3
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

732 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