Search

Star Pattern Programs in C || C Programs

Square Pattern Program

Code -

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

Output -


Hollow Square Star Pattern

int main()  
{  
 int n;  
    printf("Enter the number of rows");  
    scanf("%d",&n);  
 for(int i=1;i<=n;i++)  
    {  
 for(int j=1;j<=n;j++)  
        {  
 if(i==1 ||i==n||j==1||j==n)  
            {  
            printf("*");  
            }  
 else 
            printf(" ");  
        }  
        printf("\n");  
    }  
 
 return 0;  
}  

Output -


Hollow Square Pattern with Diagonal

#include <stdio.h> 
int main()  
{  
 int n;  
    printf("Enter the number of rows");  
    scanf("%d",&n);  
 for(int i=1;i<=n;i++)  
    {  
 for(int j=1;j<=n;j++)  
        {  
 if(i==1 ||i==n||j==1||j==n-i+1||i==j||j==n)  
            {  
            printf("*");  
            }  
 else 
            {  
 
                      printf(" ");  
                  }  
 
            }        
        printf("\n");  
    }  
 
 return 0;  
}  

Output -


Rhombus Star Pattern


Code -

#include <stdio.h> 
 
int main()  
{  
 int n;  
    printf("Enter the number of rows");  
    scanf("%d",&n);  
 for(int i=n;i>=1;i--)  
    {  
 for(int j=1;j<=i-1;j++)  
        {  
            printf(" ");  
        }  
 for(int k=1;k<=n;k++)  
        {  
            printf("*");  
        }  
        printf("\n");  
    }  
 return 0;  
}  

Output -


Hollow Rhombus Star Pattern


#include <stdio.h> 
 
int main()  
{  
 int n;  
    printf("Enter the number of rows");  
    scanf("%d",&n);  
 for(int i=n;i>=1;i--)  
    {  
 for(int j=1;j<=i-1;j++)  
        {  
            printf(" ");  
        }  
 for(int k=1;k<=n;k++)  
        {  
 if(i==1 || i==n || k==1 || k==n)  
            printf("*");  
 else 
            printf(" ");   
        }  
        printf("\n");  
    }  
 return 0;  
}  

Output -


5 views0 comments

Related Posts

See All

Program of Random Number in C || C Programs

Code - #include <stdio.h> #include <conio.h> #include <stdlib.h> void main() { // use rand() function to generate the number printf (" The random number is: %d", rand()); pri

Getchar() function in C || C Programs

Code - #include <stdio.h> #include <conio.h> void main() { char c; printf ("\n Enter a character \n"); c = getchar(); // get a single character printf(" You have passed ")

  • 1024px-Telegram_logo.svg
  • download
  • YouTube