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.

How to Display R Pattern in C with Star (*) – Step-by-Step

 C program to Print  Alphabet  R star pattern 

How to Display R Pattern in C with Star (*) – Step-by-Step




Star pattern C program to Print  Alphabet  R

Example 


#include <stdio.h>

int main()
{
    int rows;
    printf("Enter Rows = ");
    scanf("%d", &rows);


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



This C Program Print a pattern in the shape of the capital letter R using asterisks (*) 
Explain Program

Step :1

      #include <stdio.h>

Includes the standard input/output library for functions like printf() and scanf().


Step :2

     int main() {

 Start of the main function where the execution begins.

Step :3

     int rows;

    printf("Enter Rows = ");

    scanf("%d", &rows);

rows: User-defined number of rows for the pattern.

scanf reads the number from the user.

Step :4

      for (int a = 0; a < rows; a++)


Iterates over each row (a from 0 to rows - 1).

Step :5

     for (int b = 0; b < rows; b++)

For each row, prints characters in the columns (b from 0 to rows - 1).


Step :6

      if ((a == 0 || a == rows / 2) && (0 < b < rows - 1))

 When it's the first row (a == 0) or the middle row (a == rows / 2)

 AND column is not at the edges

Then print * to form the top and middle horizontal bars of the 'R'


Step :7
else if ((a != 0) && (b == 0 || (b == rows - 1 && a < rows / 2 )))

Not the first row (a != 0)
AND
First column (b == 0) → draws the left vertical line of 'R'
OR: Last column (b == rows - 1) AND row is in top half → forms top-right vertical for the top semi-circle of 'R'


Step :8

else if (b == a && a >= rows / 2)

  • For rows in the bottom half (a >= rows / 2)
  • And when b == a → diagonal
  • This draws the slanting leg of 'R' from the middle down to the bottom-right.

Step :9

else {

    printf(" ");

}

  • If none of the above conditions are met, print space.
Step :10

printf("\n");

  • Moves to the next line after finishing a row.

return 0;

Program ends 


Star pattern C program to Print  Alphabet  R
Example 

Star pattern C program to Print  Alphabet  R

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