Write in C programming for Half Pyramid of Numbers

 

Write in C programming for Half Pyramid of Numbers
Program-in-c-for-half-pyramid-of-number

Theory:

To print the half pyramid of numbers practice some "for loops" and some of nested  "if-else" conditions for better understanding.

Library functions:

  1. #include <stdio.h>
  2. #include <stdlib.h>
Here stdio.h for standard input and output functions.

Datatype:

For pattern, we use some integer type variables for loops.

Input function:

scanf(" ");

Output function:

printf(" ");


Source Code:

//The program in C for Half Pyramid of *
#include <stdio.h>
#include <stdlib.h>

int main() {
   int i, j, k;
   printf("Enter the number of rows: ");
   scanf("%d",&k);
   for (i = 1; i <= k; ++i) {
      for (j = 1; j <= i; ++j) {
         printf("%d ", j);
      }
      printf("\n");
   }
   return 0;
}


Input:

5

Output:

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

Post a Comment

Don't Post Any Spam Content!!!!

Previous Post Next Post