Write a program in C++ to display the such a pattern for n number of rows using a number which will start with the number 1 and the first and a last number of each row will be 1

.#include <iostream>
using namespace std;
void main()
{
   int i,j,n;
   cout<<"Input number of rows : ";
   cin>>n;
   for(i=0;i<=n;i++)
   {
     for(j=1;j<=n-i;j++)
cout<<" ";
     for(j=1;j<=i;j++)
       cout<<" "<<j;
       for(j=i-1;j>=1;j--)
 cout<<" "<<j;

     cout<<endl;
   }
      system ("pause");
}


Output:
1
 121
12321
Write a program in C++ to display the such a pattern for n number of rows using a number which will start with the number 1 and the first and a last number of each row will be 1 Write a program in C++ to display the such a pattern for n number of rows using a number which will start with the number 1 and the first and a last number of each row will be 1 Reviewed by Unknown on May 30, 2017 Rating: 5

No comments:

Powered by Blogger.