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 display alphabet pattern G with asterisk

C Program pattern

C Program to Print Alphabet G Star Pattern with Example


C program to Print  Alphabet  G star pattern 
Example :-


#include <stdio.h>

int main() {
    int a, b;
    int n = 7;

    for (a = 0; a < n; a++) {
        for (b = 0; b < n; b++) {
           
            if ((a == 0 ||a == n - 1) && b > 0 && b < n - 1)
                printf("*");
           
            else if ((b == 0 && a > 0 && a < n - 1))
                printf("*");
           
            else if ((a == n / 2 && b >= n / 2) || (a >= n / 2 && b == n - 1))
                printf("*");
            else
                printf(" ");
        }
        printf("\n");
    }

    return 0;
}


C Program to Print Alphabet G Star Pattern with Example
Explain Program

Step :1

#include <stdio.h>

Includes the standard input-output library to use functions like printf().

Step :2

int main() { ... }

The entry point of the program.

Step :3

int a, b;

Variables a and b are loop counters:

  • a controls rows
  • b controls columns

Step :4

int n = 7;

 dimension of the pattern is 7 × 7.

Step :5

Outer Loops

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

loop goes from row 0 to 6 (7 rows in total).

Step :6

Inner Loop: 

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

inner loop  loop goes from column 0 to 6 

Step :7

First Condition

if ((a == 0 || a == n - 1) && b > 0 && b < n - 1)


  • When the current row is the first (0) or last (6) AND
  • column is not the first or last 
Step :8

Second Condition

else if ((b == 0 && a > 0 && a < n - 1))

  • Column is the first (0) AND
  • Row is between top and bottom (i.e., not row 0 or 6)

Step :9

🔹 Third Condition

else if ((a == n / 2 && b >= n / 2) || (a >= n / 2 && b == n - 1))

(a == n / 2 && b >= n / 2)

  • Row is the middle row 
  • Column is middle or to the right 

Step :10

(a >= n / 2 && b == n - 1)

  • From the middle row down 
  • At the last column

Step :11

 Else Condition

else

    printf(" ");

  • above conditions match, just print a space.

Final Line

printf("\n");

returen 0;

C program to Print  Alphabet  G star pattern 
Output :-

c program to display alphabet pattern G  with asterisk




Related Post :-

C program to print alphabet e star

Comments

Popular posts from this blog

HTML Tag

CSS Text Color Explained with Syntax and HTML Examples

HTML Input Type Submit Syntax and Example