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 Full Pyramid of star pattern

C Program 

C Program  to Print Full Pyramid of star pattern


C Program  to Print Full Pyramid of star pattern
Example 


#include<stdio.h>
void main ()
{
int i,space,r,k=0;
   
printf("enter the number");
scanf("%d",&r);
for(i=1;i<=r;i++,k=0)
{
for(space=1;space<=r-i;space++)
{
printf(" ");
}
while(k !=2*i-1){
printf("*");
++k;
}
printf("\n");
}
return 0;
}



C Program  to Print Full Pyramid of star pattern
Explain Program

Step :1

#include <stdio.h>

  • Standard Input Output header file.
  • using printf() and scanf() functions.

Step :2

void main()

  • The program execution starts 

Step :3

Variable Declarations

int i, space, r, k = 0;

  • i: loop counter for rows.
  • space: counter for printing leading spaces in each row.
  • r: number of rows in the pyramid (user input).
k: used to control the number of asterisks (*) printed in each row

Step :4

printf("enter the number");

scanf("%d", &r);

  •  enter how many rows they want in the pyramid.

Step :5

for(i = 1; i <= r; i++, k = 0)

  • Runs from i = 1 to r
  •  iteration correspond to one row of the pyramid.
  • k = 0 resets the asterisk counter for each row.

Step :6

Inner Loop 1: Printing Leading Spaces

for(space = 1; space <= r - i; space++)

{

    printf(" ");

}

  • This prints leading spaces before the stars in each row.
  •  row number (i) increases, the number of spaces decreases.
  • centers the pyramid.

Step :7

. Inner Loop 2: Printing Stars

while(k != 2 * i - 1)

{

    printf("*");

    ++k;

}

  •  print the asterisks (*) in each row.
  •  number of stars increases by 2 with each row.
  • The formula 2 * i - 1 gives an odd number of stars (1, 3, 5, ...), forming a full pyramid.

Step :8

printf("\n");

  • After printing spaces and stars for a row, it moves the cursor to the next line.

Step :9

return 0;

C Program  to Print Full Pyramid of star pattern

 Program Output :- 

C Program  to Print Full Pyramid of star 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