Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Pls help to solve this using loops.

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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.
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.
Suggested Courses

618 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