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 display alphabet pattern L with asterisk

                                            C program pattern 

c program to display alphabet pattern L with asterisk


C program to Print  Alphabet  L star pattern 

Example 

#include <stdio.h>

int main() {
    int a,b;
    int n = 7; // height of the L

    for (a = 0; a < n; a++)
{
        for (b = 0; b < n; b++)
{
            // Print * for the left vertical line and the bottom horizontal line
            if (b == 0 || (a == n - 1 && b < n))
{
                printf("*");
            } else {
                printf(" ");
            }
        }
        printf("\n");
    }

    return 0;
}


c program to display alphabet pattern L with asterisk
Explain Program

Step :1

Header

#include <stdio.h>
  •  standard input-output library use functions like printf().

Step :2

Main Function Declaration

int main() {

  • The entry point of the program. Execution starts 

Step :3

Variable Declarations

int a, b;

int n = 7; // height of the L

  • a and b are loop counters.
  • n is the height of the letter L and also the number of rows in the output

Step :4

Outer Loop 


for (a = 0; a < n; a++)

  • Runs from a = 0 to a = 6 
 iteration of this loop correspond to one row of the output

Step :5

Inner Loop (Controls Columns)

for (b = 0; b < n; b++)

  • Run  b = 0 to b = 6 (7 iteration).
  • Each iteration of this loop correspond to one column in the current row

Step :6

.Logic to Print 

if (b == 0 || (a == n - 1 && b < n))


  • b == 0   
  • This is true for the first column in every row, Explanation we print a * in the first column of every row — forming the vertical line of the "L".
  • (a == n - 1 && b < n):
  • This is true only we are on the last row (a == 6) and b < 7 for all columns of the last row.
  • So on the last row, it prints * across the entire row — forming the bottom horizontal line of the "L".
Step :7

printf("*");

Prints an asterisk  the condition is true.

Step :8

printf(" ");

Prints a space

Step :9

printf("\n");

  •  cursor to the next line after printing each row.

C program to Print  Alphabet  L star pattern 
Output


C program to Print  Alphabet  L star pattern


Summary

  • Outer loop: controls rows.

  • Inner loop: controls what to print in each column of the row.

  • Two conditions decide where to print *:

    1. First column (b == 0)

    2. Entire last row (a == n - 1)

Related Post :-

c program to print hollow square star


Comments

Popular posts from this blog

HTML Tag

CSS Text Color Explained with Syntax and HTML Examples

CSS Outline Offset Property with Practical Examples