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 Hourglass Star Pattern

  C Program Pattern

C Program to print Hourglass  Star Pattern





 Program to print Hourglass Pattern
Example


#include <stdio.h>
 
int main()
{
  int i, j, k, rows;
 
  printf("Enter the no. of rows: ");
  scanf("%d", &rows);
 
  printf("Output: \n\n");
 
  for (i = 1; i <= rows; i++)
  {
    for (k = 1; k < i; k++)
      printf(" ");
 
    for (j = i; j <= rows; j++)
      printf("* ");
 
    printf("\n");
  }
 
  for (i = rows - 1; i >= 1; i--)
  {
    for (k = 1; k < i; k++)
      printf(" ");
 
    for (j = i; j <= rows; j++)
      printf("* ");
 
    printf("\n");
  }
 
  return 0;
}



C Program to Print Hollow Square  Star Pattern
Explain Program

Step :1

#include <stdio.h>

 standard input/output library to use functions like printf() and scanf().

Step :2

int main()

{

  int n, a, k;

Declares three integer variables:

n: number of rows for the top half of the diamond.

 k: used for looping through rows.

 a: used for spaces and asterisks within each row.

Step :3

  printf("Enter number of rows\n");

  scanf("%d", &n);

input the number of rows determines the size of the diamond

Step :4

  for (k = 1; k <= n; k++)

  {

    for (a = 1; a <= n-k; a++)

      printf(" ");

 

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

      printf("*");

 

    printf("\n");

  }

 loop prints the top half of the diamond.

Spaces: n - k spaces before stars

 Stars: 2 * k - 1 stars

 k from 1 to n row has 2 * n - 1 stars. 

Step :5

Bottom Half of the Diamond 

  for (k = 1; k <= n - 1; k++)

  {

    for (a = 1; a <= k; a++)

      printf(" ");

 

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

      printf("*");

 

    printf("\n");

  }

This loop print the bottom half of the diamond.

  Spaces: k spaces.

 Star 2 * (n - k) - 1 stars

 loop  from k = 1 to n - 1 because the middle line 

Step :6

  return 0;

}

Ends the program.


C Program to print Hourglass Pattern
Output 

C Program to print Hourglass 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