Inverted Pyramid of Numbers Pattern Program in C#
3. Write a program to print the following Pattern
4 3 2 1
4 3 2
4 3
4
Inverted Pyramid of Numbers Pattern Program in C#
3. Write a program to print the following Pattern
4 3 2 1
4 3 2
4 3
4
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Sachin SinghRank #66 · 26.2K reputationPosted Jul 30, 2022, 3:55 AM EDT
Vishal YelveRank #178 · 13.6K reputationPosted Jul 29, 2022, 1:57 AM EDT
public static void Main()
{
Console.Write("Enter Number of Rows :");
int rows = Convert.ToInt32(Console.ReadLine());
for (int i = rows; i >= 1; i--)
{
//j<=i //let rows = 5
/* first row (0 to 5) = 5 numbers (1,2,3,4,5)
* second row (0 to 4) = 4 numbers (1,2,3,4)
* third row (0 to 3) = 3 numbers (1,2,3)
* and so on
*/
//calculate stars for each row one by one
for (int j = 1; j <= i; j++)
{
Console.Write(j + " ");
}
Console.WriteLine();
}
Console.ReadLine();
}
Enter Number of Rows: 5
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Vishal JoshiRank #377 · 6.7K reputationPosted Jul 29, 2022, 2:31 AM EDT
static void printPattern(int n)
{
// Loop to print desired pattern
int curr_Index = n;
for (int line_no = n; line_no > 0;)
{
// If current index count is Greater than 0
// current line number
if (curr_Index > 0)
{
Console.Write(curr_Index + (n - line_no));
curr_Index--;
continue;
}
// Else time to print a new line
if (curr_Index <= 0)
{
Console.WriteLine();
line_no--;
curr_Index = line_no;
}
}
}
Desired Output with single Loop Only
4 3 2 1
4 3 2
4 3
4