CODE IN C

 HAL PYRAMID CODE 

Certainly! Here's an example code snippet in C to print a half pyramid pattern using asterisks (*):

#include <stdio.h> void print_half_pyramid(int rows) { int i, j; for (i = 1; i <= rows; i++) { for (j = 1; j <= i; j++) { printf("* "); } printf("\n"); } } int main() { int num_rows = 5; print_half_pyramid(num_rows); return 0; }

In this code, we have a function print_half_pyramid that takes the number of rows as a parameter and prints the half pyramid pattern using nested loops. The outer loop controls the number of rows, and the inner loop prints the asterisks for each row. After printing each row, we use printf("\n") to move to the next line.

The main function is where the print_half_pyramid function is called with num_rows = 5 as an example. You can change the value of num_rows to create a half pyramid with a different number of rows.

FULL PYRAMID CODE IN C

Certainly! Here's an example code snippet in C to print a full pyramid pattern using asterisks (*):

#include <stdio.h> void print_full_pyramid(int rows) { int i, j, space; for (i = 1; i <= rows; i++) { for (space = 1; space <= rows - i; space++) { printf(" "); } for (j = 1; j <= 2 * i - 1; j++) { printf("*"); } printf("\n"); } } int main() { int num_rows = 5; print_full_pyramid(num_rows); return 0; }

In this code, we have a function print_full_pyramid that takes the number of rows as a parameter and prints the full pyramid pattern using nested loops. The outer loop controls the number of rows, the first inner loop prints the spaces before each row, and the second inner loop prints the asterisks for each row. The number of asterisks in each row is determined by the formula 2 * i - 1, where i is the current row number.

The main function is where the print_full_pyramid function is called with num_rows = 5 as an example. You can change the value of num_rows to create a full pyramid with a different number of rows.

When you compile and run this code, it will generate the following full pyramid pattern:

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