Approach
We could solve this problem using the two loops i and j. The outer for-loop ‘i’ depicts the number of rows for the pattern, whereas the inner for-loop is for the number of columns.
C
#include <stdio.h>
int main()
{
int i,j;
//Entering row size
int row_size;
row_size = 7;
int x = 1;
int y = row_size * 2 - 1;
for (i = row_size; i >= 1; i--)
{
for (j = 1; j <= row_size * 2; j++)
{
if (j == x || j == y)
{
printf("%d", i);
}
else
{
printf(" ");
}
}
x++;
y--;
printf("\n");
}
}

You can also try this code with Online C Compiler
Run Code
Output
7 7
6 6
5 5
4 4
3 3
2 2
1
C++
#include <iostream>
using namespace std;
int main()
{
int i, j, p;
cout << "Enter the row size:";
int n;
n=6;
cout<<"Row size entered is ” <<n;
int x = 1;
int y = n * 2 - 1;
for (i = n; i >= 1; i--)
{
for (j = 1; j <= n * 2; j++)
{
if (j == x || j == y)
{
cout << i;
}
else
{
cout << " ";
}
}
x++;
y--;
cout << "\n";
}
}

You can also try this code with Online C++ Compiler
Run Code
Output
Row size entered is 6
6 6
5 5
4 4
3 3
2 2
1
Python
row_size = 4
x = 1
y = row_size*2-1
for i in range(row_size, 0, -1):
for j in range(1, row_size*2+1):
if j == x or j == y:
print(i, end="")
else:
print(" ", end="")
x += 1
y -= 1
print("\r")

You can also try this code with Online Python Compiler
Run Code
Output
4 4
3 3
2 2
1
Frequently Asked Questions
What is the difference between a do-while loop and a while loop in C++?
The significant distinction between a while loop and a do-while loop is that a while loop checks for conditions before loop iteration. On the other hand, the do-while loop tests the condition after the statements inside the loop have been executed. The while loop is also known as an entry-controlled loop. On the other hand, the exit controlled loop is known as the do-while loop.
What are do-while loops in C++? When do we use do-while loops?
The do-while loop evaluates the condition at the ending of the loop, which implies that even if the condition is never true, the statements inside the loop body will be executed at least once. The do-while loop is primarily useful when the loop must be executed at least once. It is commonly employed in menu-driven systems where the end-user determines the termination condition.
Conclusion
In this article, we have extensively discussed the program to print V-shape Number patterns using numbers. We tried to cover it with some examples.
You can look at more exciting blogs and articles curated by the coding ninja's team by visiting Library.
Recommended Readings:
Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, etc. on Coding Ninjas Studio.
Also check out some of the Guided Paths on topics such as Interview Puzzles, Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.
Do upvote our blog to help other ninjas grow.
Happy Coding!