top of page

Star Patterns Program In C - सी में स्टार पैटर्न प्रोग्राम

इस विषय में, हम सीखेंगे कि C भाषा का उपयोग करके पैटर्न कैसे बनाया जाता है। हम या तो '*' स्टार कैरेक्टर या किसी अन्य कैरेक्टर का उपयोग करके पैटर्न बनाएंगे। हम अलग-अलग पैटर्न या ज्यामितीय आकार जैसे त्रिभुज, वर्ग, आदि बनाएंगे।

< > Program Example : 01 | Square Star Pattern

वर्गाकार स्टार ( Square Star )पैटर्न बनाने के लिए कोड नीचे दिया गया है;

#include <stdio.h>  
#include <conio.h>

int main()  
{  
    int j, 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;  
}  
This Program Output Is :
Enter the number of rows: 10
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *

< > Program Example : 02 | Hollow Square Star Pattern

अब, हम खोखला वर्गाकार तारा ( Hollow Square Star ) पैटर्न बनाते हैं। इस पैटर्न के लिए स्रोत कोड नीचे दिया गया है;

#include <stdio.h>  
#include <conio.h>

int main()  
{  
    int j, 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;  
}  
This Program Output Is :
Enter the number of rows: 8
********
*      *
*      *
*      *
*      *
*      *
*      *
********

< > Program Example : 03 | Hollow Square Pattern With Diagonal

खोखले वर्ग स्टार ( Hollow Square Star ) पैटर्न के लिए कोड नीचे दिया गया है;

#include <stdio.h>  
#include <conio.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;  
}  
This Program Output Is :
Enter the number of rows: 8
*********
**     **
* *   * *
*  * *  *
*  * *  *
* *   * *
**     **
*********

 
 
 

Comments


bottom of page