Algorithm


Half Pyramid Algorithm

1. Initialize variables `i`, `j`, and `rows`.

2. Prompt the user to enter the number of rows (`rows`).

3. Use a loop (`for i`) to iterate from 1 to `rows`.

   - Use another loop (`for j`) to iterate from 1 to the current value of `i`.

   - Print a star followed by a space for each iteration of the inner loop.

   - Print a newline character after the inner loop to move to the next line.

4. End the program.

 

 

Code Examples

#1 Code Example with C Programming

Code - C Programming

#include <stdio.h>
int main() {
   int i, j, rows;
   printf("Enter the number of rows: ");
   scanf("%d", &rows);
   for (i = 1; i  < = rows; ++i) {
      for (j = 1; j  < = i; ++j) {
         printf("* ");
      }
      printf("\n");
   }
   return 0;
}
Copy The Code & Try With Live Editor

Output

x
+
cmd
*
* *
* * *
* * * *
* * * * *
Advertisements

Demonstration


C Programming Example Printing Pyramids and Patterns - DevsEnv

Next
Appending into a File in C Programming