Solution
C
The source code for the C program that prints rectangles using descending numbers is as follows:
#include<stdio.h>
int main() {
printf("Enter the row size: ");
int row_size, output, input;
scanf("%d", &row_size);
for(output=row_size; output>=1; output--){
for(input=row_size; input>=1; input--){
printf("%d", input);
}
printf("\n");
}
}

You can also try this code with Online C Compiler
Run Code
Output:

C++
The source code for the C++ program that prints rectangles using descending numbers is as follows:
#include<iostream>
using namespace std;
int main() {
cout<<"Enter the row size: ";
int row_size, output, input;
cin>>row_size;
for(output=row_size; output>=1; output--){
for(input=row_size; input>=1; input--){
cout<<input;
}
cout<<"\n";
}
}

You can also try this code with Online C++ Compiler
Run Code
Output:

Python
The source code for the Python program that prints rectangles using descending numbers is as follows:
print("Enter the row size: ")
row_size=int(input())
for output in range(row_size, 0, -1):
for i in range(row_size, 0, -1):
print(i, end="")
print("\r")

You can also try this code with Online Python Compiler
Run Code
Output:

Java
The source code for the Java program that prints rectangles using descending numbers is as follows:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
System.out.println("Enter the row size:");
int row_size, output, input;
row_size=cs.nextInt();
for(output=row_size; output>=1; output--) {
for(input=row_size; input>=1; input--)
System.out.print(input);
System.out.println();
}
cs.close();
}
}

You can also try this code with Online Java Compiler
Run Code
Output:

Frequently Asked Questions
What are rectangles using descending numbers?
This is a simple pattern with the digits in a row repeated in decreasing order in the rectangular pattern.
For instance,
321
321
321
What is the time complexity for rectangles using descending numbers in C++?
The time complexity for rectangles using descending numbers is O(N2) as we're iterating through two nested for loops, each of which has a range of N to 0.
When one loop is within the other loop, what do we call it?
One loop within another loop is referred to as a "nested loop".
What is the purpose of print("\r") in the Python code?
"\r" moves the cursor to the beginning of the line and then resumes normal text production.
Is it possible to enter a negative number?
No, we are not able to enter negative numbers since the number must be non-negative due to the problem constraint.
Conclusion
In this blog, we learned about the concepts of rectangles using descending numbers patterns in various languages like C, C++, Python and Java.
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 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.