Have you ever tried doing some pyramid of numbers as in the given
1
123
12345
123
1
The program here works for at most 7 digits
Program compiled and executed in turboc++
#include<iostream.h>
#include<conio.h>
void main()
{
long int i=0,n,j=1,k;
clrscr();
cout<<"Enter any Odd digit number\t";
R:cin>>n;
if((n%2)==0)
{
cout<<"The number you entered is not odd.Enter an odd number\n";
goto R;
}
else
{
cout<<"The Pyramid sequence is\n";
for(k=0;k<=((n-1)/2);k++)
{
for(int x=0;x<=(((n-1)/2)-k);x++)
cout<<" ";
i=(i*10)+(j+k);
cout<<i<<endl;
j++;
i=(i*10)+(j+k);
}
i=(i/10);
int y=1;
for(k=((n+1)/2);k<n;k++)
{
y++;
int z=y;
do
{
cout<<" ";
z--;
}while(z!=0);
i=(i/100);
cout<<i<<endl;
}
}
getch();
}
0 comments
Post a Comment