Create Your First Functional Component in React JS – Beginner's Guide

Image
Create Your First Functional Component in React JS  1. Introduction When you start learning React JS, one of the first things you will come across is the concept of components. At first, components may seem like just another programming concept, but they are actually the foundation of almost every React application. Think about a website you use every day. It may have a header, navigation menu, login form, product section, and footer. Instead of writing all these elements together in one large file, React allows us to create separate parts and manage them independently. These separate parts are called components. In this tutorial, we are going to create our first functional component in React. We will start with a very simple example and gradually understand how components are created, exported, imported, and displayed on a webpage.  2. What Is a Functional Component in React?   A functional component is simply a JavaScript function that returns a user interface using JSX...

C Program to Print Hollow Full Pyramid Using Stars Pattern

C Program to print Hollow Full pyramid star Pattern

C Program to Print Hollow Full Pyramid Using Stars Pattern



C Program to print Hollow Full pyramid star Pattern

Example :-


#include<stdio.h>
int main()

{
int i, space, row, star=0;


printf("Enter The Number ");
scanf("%d",&row);


for(i = 0; i < row-1; i++) {
for(space = 1; space < row-i; space++) {
printf(" ");
}


for (star = 0; star <= 2*i; star++) {
if(star==0 || star==2*i)


printf("*");
else
printf(" ");
}
printf("\n");
}


for(i=0; i<2*row-1; i++){
printf("*");


}
return 0;
}


C Program to Print Hollow Full Pyramid Using Stars Pattern

Explain Program

Step :1

#include <stdio.h>

int main()

{

    int i, space, row, star = 0;


#include <stdio.h> :-  printf and scanf.

 int i, space, row, star;: Declares loop variables and input variable.

 row = number of levels of the pyramid.

 i = controls outer loop (rows).

 space = manages indentation before the stars.

 star = controls how many positions are printed per row.

Step :2

User Input

printf("Enter The Number ");

scanf("%d", &row);

User input how many rows they want for the pyramid.

 If input is 5, the pyramid 

Step :3

Hollow Pyramid

for(i = 0; i < row - 1; i++) {

    for(space = 1; space < row - i; space++) {

        printf(" ");

    }

     for(star = 0; star <= 2 * i; star++) {

        if(star == 0 || star == 2 * i)

            printf("*");

        else

            printf(" ");

    }

     printf("\n");

}

How it work:

  •  Loop 1)  for (i = 0; i < row - 1; i++)
  • Controls each row of the hollow pyramid .
  •  Runs row - 1 times (e.g., if row = 5, this loop runs 4 times).
  •  Loop 2)  for (space = 1; space < row - i; space++)
  • Adds spaces to align the stars in a pyramid shape.

Step :4

for(star = 0; star <= 2*i; star++)

Handle the character in the current row.

Always print * at the start (0) and end (2*i).

 In between, print a space to make it hollow.

 Step :5

Bottom Part:

for(i = 0; i < 2 * row - 1; i++) {

    printf("*");

}

loop prints a full base of stars at the bottom.


C Program to print Hollow Full pyramid star Pattern
Output :-

C Program to print Hollow Full pyramid star Pattern

Related Post :-

C program t -prin rhombus star pattern

c program to print floyds triangle

c program to print pascals triangle

Comments

Popular posts from this blog

HTML Tag

CSS Text Color Explained with Syntax and HTML Examples

CSS Outline Offset Property with Practical Examples