Pattern Programs in C | Inverted Half Pyramid

In this post, we will learn about Pattern Programs in c which is Inverted half pyramid. So let’s start our easy understanding tutorial.

What You Should Know?

To understand this example, you should know about the following C programming topics:

  • pattern programs in c|part-2
  • what is for loop in c programming.
  • what is use of <stdio.h>.
  • what is main() function in c programming
  • what is  scanf() and printf()

Pattern Programs in c | Inverted Half Pyramid

we talk inverted half pyramid  program in c language with a star(*) and numbers pattern examples.

Example-1

#include<stdio.h>

int main() {
   int row, column, total_rows;

   printf("Enter number of rows: ");
   scanf("%d", &total_rows);
   for (rotal_rows; row >= 1; row--) {
      for (column = 1; column <= row; column++) {
         printf("* ");
      }
      printf("\n");
   }
   return 0;
}

Output

* * * * *
* * * *
* * *
* *
*

Example-2

#include<stdio.h>

int main() {
   int row, column, total_rows;
   printf("Enter number of rows: ");
   scanf("%d", &total_rows);
   for (row = total_rows; row >= 1; row--) {
      for (column = 1; column <= row; column++) {
         printf(" %d ", column);
      }
      printf("\n");
   }
   return 0;
}

Output

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Example-3

#include<stdio.h>

int main() {
   int row, column, total_rows;
   printf("Enter number of rows: ");
   scanf("%d", &total_rows);
   for (row = total_rows; row >= 1; row--) {
      for (column = 1; column <= row; column++) {
         printf(" %d ", row);
      }
      printf("\n");
   }
   return 0;
}

Output

5 5 5 5 5
4 4 4 4
3 3 3
2 2
1

Example-4

#include<stdio.h>

int main() {
   int row, column, total_rows;
   int x = 1;

   printf("Enter number of rows: ");
   scanf("%d", &total_rows);
   for (row = total_rows; row >= 1; row--) {
      for (column = 1; column <= row; column++) {
         printf(" %d ", x);
         x++;
      }
      printf("\n");
   }
   return 0;
}

Output

1 2 3 4 5
6 7 8 9
10 11 12
13 14
15

Leave a Reply

avatar
  Subscribe  
Notify of