Write Complete Code Fragments in space below. Remember your code should be well documented. The following pattern
Write Complete Code Fragments in space below. Remember your code should be well documented.
The following pattern
Sample Output:
Programming language is missing in the question. So we will answer this program in C++ language. If you want this program to be executed in some other programming language, kindly resubmit the question with a specific programming language.
A C++ program is as follows,
File name: “main.cpp”
#include <iostream>
using namespace std;
int main()
{
//Declare the variable
int i, j, k, space, n;
cout<<"Enter number of rows: ";
cin >> n;
cout << " ";
//Loop through n rows
for (i=1; i<=n; i++)
{
//Loop for space at the beginning
for (j=1; j<=n-i; j++)
cout << " ";
//Loop to print the values
for (j=1,k=2*i-1; j<=2*i-1; j++,k--)
{
if (j <= k)
cout << " "<<j;
else
cout << " "<<k;
}
//Print new line
cout << endl;
//Print space
cout << " ";
}
return 0;
}
Step by step
Solved in 4 steps with 3 images