#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 want is

    1
   121
  12321
 1234321
123454321

like a pyrmiad

but i get 
1
12
123
1234
12345....

Well, you can get it to count up, so now you need to get it to count up and then back down again on the same line. How about stopping at half of what you were stopping at, then printing j until it reaches 0?

for ( i = 1; i <= N; i++ ) {  
  for ( j = 1; j <= N - i; j++ )
    cout<<" ";

  for ( j = 1; j < i; j++ )
    cout<< j;

  do
    cout<< j;
  while ( j-- > 1 );

  cout<<'\n';
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.