0

Hi friends

i had a assignment to make this c++ program

output

f e d c b a 
  e d c b a 
    d c b a
      c b a 
        b a
          a

i have created this program using this code

# include <iostream.h>
  # include <conio.h>
  void main(void)
  {
char x[6];
  int m=0;
  int n=70;
  int z=0;
  int p=32;
  int b=1 ;
  while(m<6)
  {
  x[m]=n;

  n=n-1;
  m++;

  }
 while(z<6)
  {

  int f=0;
    while(f<6)
    {

    cout<<x[f];
    x[z]=p;
    cout<<x[z];
    f++;
    }
cout<<endl;
    z++;
    }

    }




but its output is 




    f e d c b a 
        d c b a
          c b a 
            b a
              a

if somebody help me than i will be very thankful to you

Regards

2
Contributors
1
Reply
3
Views
4 Years
Discussion Span
Last Post by Ancient Dragon
0

You don't need arrays or while loops. Just use three simple for loops. The first counts the number of rows, which is 6. The second displays space(s) to move the cursor on the screen, and the third displays the letters in reverse order that they appear in the alphabet.

loop counts from 0 to 6 // you need 6 rows of data on the screen
   loop counts from 0 until it reaches the value of first counter
      display a space
   loop counts from 'F' - value of first counter, down until it reaches 'A'
       display char value of the counter

Edited by Ancient Dragon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.