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

Diamond pattern in C

C Program: Diamond Star Pattern

πŸ”· C Program: Diamond Star Pattern

#include<stdio.h>
int main()
{
    int num;
    printf("Enter the number:\n");
    scanf("%d",&num);

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

    // Lower Half
    for(int i=num; i>=1; i--)
    {
        for(int k=num; k>=i; k--)
        {
            printf(" ");
        }
        for(int j=1; j<=i; j++)
        {
            printf("* ");
        }
        printf("\n");
    }

    return 0;
}
  

πŸ“˜ Explanation:

This C program prints a full diamond star pattern. It first constructs the top half of the diamond using an upright pyramid of stars with leading spaces for alignment. The bottom half is constructed using an inverted pyramid.

- The outer loops run for `num` lines each for the top and bottom halves. - The inner loops handle spacing and star printing. - Spacing ensures the stars are centered, forming a symmetric diamond shape.

πŸ” Sample Output:

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

🏷️ Keywords:

C star pattern, diamond pattern in C, full diamond program, half pyramid in C, inverted pyramid, star shape printing in C, C loop practice

Comments

Popular Posts

πŸŒ™