Conditional Rendering in React Complete Guide with Examples 2026

Image
  Conditional Rendering in React Conditional Rendering is one of the most useful concepts in React. It means showing different content on the screen depending on a condition. For example: If a user is logged in → show Logout If a user is not logged in → show Login If a student has passed → show Congratulations If a product is available → show Buy Now If data is loading → show Loading... React does not have a separate if rendering tag. Instead, we use normal JavaScript conditions such as if, the ternary operator, &&, and switch to decide what should appear in the UI.

C Program To Print Swastik Pattern

C Program To Print Swastik Pattern


C Program To Print Swastik Pattern
Example 


#include<stdio.h>
int main()
{
     
int a,b,n;
     
printf("Enter Swastik Size(n):");

     scanf("%d",&n);

     printf("* ");
   
     
for(a=0; a<n-2; a++)

           printf("  ");
   
     
for(a=0; a<n; a++)  
           
printf("* ");
   
     
printf("\n");
   
     
for(b=0; b<n-2; b++)
     {
           
printf("* ");
           
for(a=0; a<n-2; a++)
               
printf("  ");
           
printf("* \n");
     }
   
     
for(a=0; a<n*2-1; a++)    
           
printf("* ");
     
printf("\n");
   
     
for(b=0; b<n-2; b++)
     {
           
for(a=0; a<=n-2; a++)
               
printf("  ");

           printf("* ");

           for(a=0; a<n-2; a++)

                printf("  ");

           printf("* \n");
     }

     for(a=0; a<n; a++)  

           printf("* ");

     for(a=0; a<n-2; a++)

           printf("  ");

     printf("* ");  

     return 0;
}


C Program To Print Swastik Pattern

Explain Program

Step :1

Header

#include <stdio.h>
  •  standard input-output library use functions

Step :2

Main Function Declaration

int main() {

  • The entry point of the program. Execution starts 

Step :3

int a, b, n;

Declare loop variables a, b, and n where:

n: The size of the Swastik.

 a, b: Loop counters for row and column logic.

Step :4

printf("Enter Swastik Size(n):");

scanf("%d", &n);

 user to enter the size of the Swastik symbol.

Input is stored in variable n.

Step :5

printf("* ");

for (a = 0; a < n - 2; a++)

     printf("  ");

for(a = 0; a < n; a++) 

    printf("* ");

printf("\n");

 Explanation:

 prints the top part of the Swastik 

Let's say n = 7, this will print:

Step :6

for(b = 0; b < n - 2; b++)

{

    printf("* ");

    for(a = 0 ; a < n - 2; a++)

        printf("  ");

    printf("* \n");

}

Step :7

for(a = 0 ; a < n * 2 - 1; a++)   

    printf("* ");

printf("\n");

Explanation:

 center horizontal bar of the Swastik.

 

n*2  - 1 stars are print in one row.

 n = 7, prints 13 stars (i.e., 2n - 1 = 13):

Step :8

for(b = 0; b < n - 2; b++)

{

    for(a = 0; a <= n - 2; a++)

        printf("  ");

    printf("* ");

    for(a =  0 ; a < n - 2; a++)

        printf("  ");

    printf("* \n");

}

Explanation:

Prints (n-2) rows again.

Step :9

for(a = 0; a < n; a++) 

    printf("* ");

for(a = 0; a < n - 2; a++)

    printf("  ");

printf("* "); 

* Explanation:

Prints the bottom part of the Swastik.

For n = 7,

C Program To Print Swastik Pattern

 Program Output 

C Program To Print Swastik Pattern

                          

Related Post :-

Comments

Popular posts from this blog

HTML Tag

CSS Text Color Explained with Syntax and HTML Examples

HTML Input Type Submit Syntax and Example