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

                                                C program  pattern 

 

c program to display alphabet pattern K with asterisk


 C program to Print  Alphabet  K star pattern 

Example 

#include <stdio.h>

int main()
{
    int a, b;
    int height = 7;
// Height of the K

    for(a = 0; a < height;a++)
{
        printf("*");
// First vertical line

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

    return 0;
}
 

c program to display alphabet pattern K with asterisk

Explain Program

  Step :1

Header File
#include <stdio.h>
Step :2
 Main Function
int main()
{
  •  execution of the program 
Step :3
Variable Declarations
int a, b;
int height = 7;
  • a: loop counter for rows.
  • b: loop counter for columns.
  • height = 7: defines the number of rows in the output 
Step :4

Outer Loop
for (a = 0; a < height; a++)
  • Loop from a = 0 to a = 6 → 7 rows in total.

Step :5

         First Vertical Line

printf("*");
  • Prints a * at the start of every line →
  • This forms the vertical left leg of the letter 'K'.
Step :6
. Inner Loop
for (b = 0; b < height; b++)
  • Loop from b = 0 to b = 6 → Control  print after the first star on each row.
Step :7
Diagonal Logic of 'K'
if (a + b == height / 2 || a - b == height / 2)
 break this condition:
  • height / 2 = 7 / 2 = 3 
  • a + b == 3 → Draws the upper diagonal arm of the 'K'.
  • a - b == 3 → Draws the lower diagonal arm of the 'K'.
Step :8

       Printing * or Space

printf("*");
  • If the condition is true → prints a *.
printf(" ");
  • Else → prints a space to maintain alignment.
Step :9
New Line After Each Row
printf("\n");
  • Moves to the next line 
Step :10
. Return Statement
return 0;

 

C program to Print  Alphabet  K star pattern 
Output





Comments

Popular posts from this blog

HTML Tag

CSS Text Color Explained with Syntax and HTML Examples

HTML Input Type Submit Syntax and Example