CPP Program to print number Rhombus

Number rhombus is one of the best example to teach and show mastery on looping at any stage. The rhombus program is here,This example was developed  in windows 10 environment using DEV C++ IDE but you can run this program in any environment as we have not used any environment specific libraries.

/*	Program to print the rhombus of numbers
	made by		: rakesh kumar
*/
#include
#include
#include
using namespace std;
int main()
{
	int n,i,j,k,l;
	//input phase
	cout<"\n Enter any number n : "; cin>>n;
	
	//processing + output
	cout<<" Number Rhombus \n";
	for(i=1;i<=n;i++)
	 {
	 	for(j=1;j<=n-i;j++)
	 	   cout<<setw(3)<<' ';
	 	for(k=1;k<=i;k++)
	 		cout<<setw(3)<<k; for(l=i-1;l>=1;l--)
	 		cout<<setw(3)<<l;
	 	cout<<endl; } for(i=n-1;i>=1;i--)
	 {
	 	for(j=1;j<=n-i;j++)
	 	   cout<<setw(3)<<' ';
	 	for(k=1;k<=i;k++)
	 		cout<<setw(3)<<k; for(l=i-1;l>=1;l--)
	 		cout<<setw(3)<<l;
	 	cout<<endl;
	 }
	return 0;
}

Here is the out put of the same program.

rhombus of number

%d bloggers like this: