Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,179 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,369 people online right now. Registration is fast and FREE... Join Now!




creating the pyrmaid with numbers

 
Reply to this topicStart new topic

creating the pyrmaid with numbers

asad12
7 Jul, 2008 - 10:20 AM
Post #1

New D.I.C Head
*

Joined: 7 Jul, 2008
Posts: 4

here's my code
cpp
#include<iostream>
using namespace std;
int main()


{
int i,N=5,j;
for (i=1; i<=N; i++)
{
for (j=1; j<= N-i; j++)
{
cout << " ";
}

for (j=1; j<=2*i-1; j++)
{
cout << j ;
}
cout << endl;
}
return 0;
}




the display i get is
CODE

      1
     12
    123
   1234
  12345

but the display i want is
CODE

       1
      121
    12321
   1234321
  123454321

like a pyrmaid ,
i am not sure where i am making a mistake

Mod Edit:
Please code.gif
Thanks, gabehabe smile.gif

This post has been edited by asad12: 7 Jul, 2008 - 11:28 AM
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Creating The Pyrmaid With Numbers
7 Jul, 2008 - 11:32 AM
Post #2

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,556



Thanked: 99 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
I think you're looking for something like this:
cpp
#include<iostream>

using namespace std;

int main()
{
int i,N=5,j;
for (i=1; i<=N; i++)
{
for (j=1; j<= N-i; j++)
cout << " ";

for (j=1; j<=i; j++)
{
cout << j ;
if (j == i)
for (int k = j-1; k > 0; k--)
cout << k;
}

cout << endl;
}
cin.get ();
return EXIT_SUCCESS;
}

Note the if statement is the biggest addition to your code.

Hope this helps smile.gif
User is online!Profile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 11:02AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month