C++ program to print number pyramid 1 121 12321 1234321 using class.
Note: Use new compiler (Code blocks or Dev C++) to run these C++ programs. Old Turbo C compiler does not supports some new features of C++.
If you want to run these programs on old Turbo C++ compiler use <iostream.h> instead of <iostream> , do not use ( using namespace std; ) , use { getch(); } to hold run-time screen , use void main() instead of int main() .
If you want to run these programs on old Turbo C++ compiler use <iostream.h> instead of <iostream> , do not use ( using namespace std; ) , use { getch(); } to hold run-time screen , use void main() instead of int main() .
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
#include<iostream>
using namespace std;
class xyz
{
public:
void display()
{
int i, j, k, l, x=3;
for(i=1; i<=4; i++)
{
for(j=0; j<=x; j++)
cout <<" ";
for(k=1; k<=i; k++)
cout <<k;
for(l=i-1; l>0; l--)
cout <<l;
x = x-1;
cout <<"\n";
}
}
};
int main()
{
xyz a;
a.display();
return 0;
}
Comments
Post a Comment