?
Solved

Pls help to solve this using loops.

Posted on 2004-08-10
3
Medium Priority
?
259 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files 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.
Suggested Courses

752 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