4 Replies - 343 Views - Last Post: 09 March 2010 - 08:52 AM Rate Topic: -----

#1 suravi6990  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 19-September 09

C++ code problem

Posted 09 March 2010 - 07:47 AM

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
 char i,j,m,k;
 clrscr();
 cout<<endl<<endl;
  for(j='A'-1; j<='D'; j++)
   {
     for(m=j; m<'D'; m++)
      {
	cout<<" ";
      }
     for(k='A'; k<=j; k++)
      {
	cout<<k;
      }
     for(i=j+1; i>='A'; i--)
      {
	cout<<i;
      }
     cout<<endl;
   }
getch();
}


This gives the output as:
....A
...ABA
..ABCBA
.ABCDCBA
ABCDEDCBA

How do I modify the code to get:
ABCDEDCBA
.ABCDCBA
..ABCBA
...ABA
....A


pLEASE HELP me fast!

This post has been edited by NickDMax: 09 March 2010 - 07:58 AM
Reason for edit:: Fixed formatting


Is This A Good Question/Topic? 0
  • +

Replies To: C++ code problem

#2 Anarion  Icon User is offline

  • The Persian Coder
  • member icon

Reputation: 282
  • View blog
  • Posts: 1,455
  • Joined: 16-May 09

Re: C++ code problem

Posted 09 March 2010 - 07:52 AM

If you wrote this program, you should be able to do the reverse... :)

Edit: Also, this code is deprecated! look at the headers... they have to be:
#include<iostream>
#include<conio.h> //my compiler doesn't even support this header, it's C only
#include<cmath>



Also, main must return an int. void is wrong:
int main() {
    //code goes here
    return 0; //indicates the program is over to the OS
}

This post has been edited by Anarion: 09 March 2010 - 07:54 AM

Was This Post Helpful? 1
  • +
  • -

#3 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2209
  • View blog
  • Posts: 9,183
  • Joined: 18-February 07

Re: C++ code problem

Posted 09 March 2010 - 08:00 AM

Well I guess I would look at reversing the outer loop...
Was This Post Helpful? 1
  • +
  • -

#4 Guest_suravi6990*


Reputation:

Re: C++ code problem

Posted 09 March 2010 - 08:44 AM

Sorry guys, i could not still do the reverse
please help
Was This Post Helpful? -1

#5 joesyuh  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 174
  • Joined: 30-September 08

Re: C++ code problem

Posted 09 March 2010 - 08:52 AM

As Nick said you might want to reverse a loop somewhere... HINT HINT... NUDGE NUDGE... WINK WINK...
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1