Code to generate the pyramid structure using c++

Code to generate the pyramid structure using c++


 main()  
 {  
 int i;  
 int j,n,uppr,lowr, arry[] = {1,2,3,4,5,6,7,8,9};  
 /*Take Input */  
 do  
 {  
 cout << "Enter an odd number(0-9):";  
 cin >> n;  
 if(n < 0 || n > 9 || ((n % 2) == 0))  
 cerr << "Error" << endl;  
 }while(n < 0 || n > 9 || ((n % 2) == 0));  
 /*Generate the pyramid structure */  
 for(i = 0; i < n; i++)  
 {  
 for(j = 0; j < ((i < (n-i-1)?i:(n-i-1))); j++)  
 cout << " ";  
 lowr = (i < (n-i-1)) ? i : (n-i-1);  
 uppr = (i < (n-i-1)) ? (n-i-1) : i;  
 for( j = lowr; j <= uppr; j++)  
 cout << arry[j];  
 cout << endl;  
 }  
 return 0;  
 }  

To execute something before main function you can try below code


 fun()  
 {  
 clrscr();  
 printf("\nIn the fun..........");  
 }  
 #pragma startup fun  
 int main()  
 {  
 printf("\nIn the main()");  
 getch();  
 return 0;  
 }