Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

๐Ÿ”ท Square Star Pattern ๐Ÿ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } ๐Ÿ”ท Reverse Square Alphabet Pattern (Column-wise) ๐Ÿ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } ๐Ÿ”ท Reverse Square Alphabet Pattern (Row-wise) ๐Ÿ“‹ Copy Code #include <stdio.h> int main() { int num; ...

Dual Half Pyramid Star Pattern in C

Inverted and Upright Half Pyramid in C

Inverted and Upright Half Pyramid in C

This C program prints a symmetrical V-shaped pattern using asterisks (*). It first prints an inverted half pyramid followed by a normal half pyramid using nested for loops.

✅ C Program Code:


#include <stdio.h>

int main()
{
    int num;
    printf("Enter the number:\n");
    scanf("%d", &num);

    // Inverted half pyramid
    for (int i = 1; i <= num; i++)
    {
        for (int j = i; j <= num; j++)
        {
            printf("* ");
        }
        printf("\n");
    }

    // Upright half pyramid
    for (int i = 1; i <= num; i++)
    {
        for (int j = i; j >= 1; j--)
        {
            printf("* ");
        }
        printf("\n");
    }
}
  

๐Ÿ’ก Explanation:

  • The first loop prints the inverted half pyramid (top part) with decreasing number of stars.
  • The second loop prints the upright half pyramid (bottom part) with increasing number of stars.
  • This creates a V-shaped pattern using asterisks.

๐Ÿ’ป Sample Output:

Enter the number:
4
* * * *
* * *
* *
*
*
* *
* * *
* * * *

๐Ÿ” Keywords:

Star pattern in C, V star pattern, inverted pyramid in C, C pattern practice, nested loops C programs, symmetric pattern using C

Comments

Popular Posts

๐ŸŒ™