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; ...

C Pattern Program: Hourglass Star Shape

C Pattern Program: Hourglass Star

πŸ”· C Pattern Program: Hourglass Star Shape

#include <stdio.h>

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

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

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

    return 0;
}
  

πŸ“˜ Explanation:

This C program prints a vertical hourglass-like star pattern using spaces and a single * per row.

πŸ”Ή The first loop prints the upper half: decreasing spaces followed by a star.
πŸ”Ή The second loop prints the lower half: increasing spaces followed by a star.
πŸ”Ή Together, it creates a symmetrical hourglass shape centered around the vertical axis.

πŸ” Sample Output:

Enter the number: 5
    *
   *
  *
 *
*
 *
  *
   *
    *
    

🏷️ Keywords:

C pattern printing, star pattern, diamond pattern, vertical hourglass, single star pattern, C loop pattern examples

Comments

Popular Posts

πŸŒ™