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 N with asterisk

 C program to Print  Alphabet  N star pattern 

c program to display alphabet pattern N with asterisk


C program to Print  Alphabet  N star pattern 
Example 


#include <stdio.h>

int main()
{
    int a,b;
    int n = 7; // height of the N (can be adjusted)

    for (a = 0; a < n; a++)
{
        for (b = 0; b < n; b++)
{
            // Print * for the first column, last column, and diagonal
            if (b == 0 || b == n - 1 || b == a)
                printf("*");
            else
                printf(" ");
        }
        printf("\n");
    }

    return 0;
}


c program to display alphabet pattern N with asterisk
Explain Program

Step :1

#include <stdio.h>

This includes the Standard Input Output library. It is necessary to use functions like printf() for output.

Step :2

int main()

This is the main function from where the execution of the program 

Step :3

int a, b;

These are loop variables:

  • a: for controlling rows
  • b: for controlling columns

Step :4

int n = 7;

 defines the height (and width) of the pattern. The 'N' pattern will be print in a 7x7 grid. You can change n to any positive integer to scale the size of the 'N'

Step :5

Outer Loop: 

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

This controls the rows of the pattern.

  • a = 0 to a = 6 ( n = 7)
  • For each value of a, one full line (row) of output is printed

Step :6

Inner Loop:

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

This controls the columns within each row.

  • b = 0 to b = 6 for each row

Step :7

Conditional:

 if (b == 0 || b == n - 1 || b == a)

This is the heart of the logic. It decides where to print an asterisk *.

  • b == 0: First column → left vertical line of the 'N'
  • b == n - 1: Last column → right vertical line of the 'N'
  • b == a: Diagonal  top-left to bottom-right (row index == column index)

If any of the three conditions is true, print a *. Otherwise, print a space ( ).

Step :8

printf("*"); 


 printf(" ");

  • Print a * when the condition is met (position of vertical or diagonal part of 'N')
  • Print a space otherwise

Step :9

printf("\n");

After each row is completed move courser next line to start the next

C program to Print  Alphabet  N star pattern 
Output

C program to Print  Alphabet  N star pattern

Related Post :-

C program to print alphabet k star Pattern

C program to prin alphabet j star Pattern

Comments

Popular posts from this blog

HTML Tag

CSS Text Color Explained with Syntax and HTML Examples

HTML Input Type Submit Syntax and Example