ad

Tuesday, March 11, 2025

C Program print Inverted Right Half Pyramid Star Pattern

https://webdesigningtheory.blogspot.com/
C Program print Inverted Right Half Pyramid  Star Pattern

Example :- 

//inverted half pyramidoc c language


#include<stdio.h>
int main()
{
int i,j,row;
printf
("enter number row");
scanf("%d",&row);
for(i=row;i>=1;i--)
{
for
(j=1;j<=i;j++)
{
printf
("*");
}
printf
("\n");
}
getch
();
}


C Program print Inverted Right Half Pyramid  Star Pattern

Explain Program

Step :1

#include<stdio.h>

  • Standard Input Output header file.
  • Functions like printf() and scanf() are defined in stdio.h.

Step :2

int main()

  • main function

Step :3

int i, j, row;

  • Declares three integer variables:
  • row: stores the number of rows of the triangle (user input).
  • i and j: loop control variables used in for loops.

Step :4

printf("enter number row");
  •  user to enter the number of rows.

Step :5

scanf("%d",&row);

  •  input, stores to  the variable row.
  • %d tells the compiler you're expecting an integer

Step :6

for(i=row; i>=1; i--)

  • outer loop which run from row downs to 1.
  • It control the number of line (or rows) to print.

Step :7

for(j=1; j<=i; j++)

  • This is the inner loop which prints the asterisks * in each row.
  • On each line, the number of asterisks equals the current value of i.

Step :8

printf("*");

  • Prints one asterisk without a newline.

Step :9

printf("\n");

  •  prints a newline to move to the next row.

getch();


C Program print Inverted Right Half Pyramid  Star Pattern

Program Output :-



Related Post :-


Monday, March 10, 2025

C Program Print Inverted Pyramid and pattern

C Program Print Inverted Pyramid and pattern

C Program Print Inverted Pyramid and pattern

Example 


#include<stdio.h>
int main()
{

int i,j,row;
printf("enter number row");
scanf("%d",&row);
for(i=row;i>=1;i--)
{

for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch ();
}





C Program Print Inverted Pyramid and pattern

Explain Program

Step :1

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 i, j, row;

Declares three integer variables:

i and j are loop counters.

Step :4

printf("enter number row");

printf("Enter number of rows: ");

integer input from the user and stores it in the variable row

Step :5

for(i=row; i>=1; i--)

for(i=row; i>=1; i--)

 outer loop that controls the number of rows.

  user-input number (row) and decreases by 1 each time until it reaches 1.

 Step :6

for(j=1; j<=i; j++)

for(j=1; j<=i; j++)

 inner loop which prints asterisks * in each row.

  prints i number of asterisks. 

Step :7

printf("*");

printf("*");

Prints one asterisk on the same line (no newline character).

 Step :8

printf("\n");

printf("\n");

After printing all the asterisks in one row, this moves the cursor to the next line.

  each row of asterisks is printed on a new line.

 Step :9

getch();

C Program Print Inverted Pyramid and pattern

 Program Output 

C Program Print Inverted Pyramid

Related Post :-

Website about us page html and css

Sunday, March 9, 2025

C Program To Print Swastik Pattern

C Program To Print Swastik Pattern

C Program To Print Swastik Pattern

Example 


#include<stdio.h>
int main()
{
     
int a,b,n;
     
printf("Enter Swastik Size(n):");

     scanf("%d",&n);

     printf("* ");
   
     
for(a=0; a<n-2; a++)

           printf("  ");
   
     
for(a=0; a<n; a++)  
           
printf("* ");
   
     
printf("\n");
   
     
for(b=0; b<n-2; b++)
     {
           
printf("* ");
           
for(a=0; a<n-2; a++)
               
printf("  ");
           
printf("* \n");
     }
   
     
for(a=0; a<n*2-1; a++)    
           
printf("* ");
     
printf("\n");
   
     
for(b=0; b<n-2; b++)
     {
           
for(a=0; a<=n-2; a++)
               
printf("  ");

           printf("* ");

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

                printf("  ");

           printf("* \n");
     }

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

           printf("* ");

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

           printf("  ");

     printf("* ");  

     return 0;
}


C Program To Print Swastik Pattern

Explain Program

Step :1

Header

#include <stdio.h>
  •  standard input-output library use functions

Step :2

Main Function Declaration

int main() {

  • The entry point of the program. Execution starts 

Step :3

int a, b, n;

Declare loop variables a, b, and n where:

n: The size of the Swastik.

 a, b: Loop counters for row and column logic.

Step :4

printf("Enter Swastik Size(n):");

scanf("%d", &n);

 user to enter the size of the Swastik symbol.

Input is stored in variable n.

Step :5

printf("* ");

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

     printf("  ");

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

    printf("* ");

printf("\n");

 Explanation:

 prints the top part of the Swastik 

Let's say n = 7, this will print:

Step :6

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

{

    printf("* ");

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

        printf("  ");

    printf("* \n");

}

Step :7

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

    printf("* ");

printf("\n");

Explanation:

 center horizontal bar of the Swastik.

 

n*2  - 1 stars are print in one row.

 n = 7, prints 13 stars (i.e., 2n - 1 = 13):

Step :8

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

{

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

        printf("  ");

    printf("* ");

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

        printf("  ");

    printf("* \n");

}

Explanation:

Prints (n-2) rows again.

Step :9

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

    printf("* ");

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

    printf("  ");

printf("* "); 

* Explanation:

Prints the bottom part of the Swastik.

For n = 7, outputs:

C Program To Print Swastik Pattern

 Program Output 


                          

Related Post :-


triangle patterns in php program

Friday, March 7, 2025

Write C Program To Print Multiplication Table using For Loop

C Program 

Write  C Program  To Print  Multiplication Table  using For Loop



Write  C Program  To Print  Multiplication Table  using For Loop

Examples :-    


#include<stdio.h>

void main()
{
int n,i;

printf("Enter Any Number:");
scanf("%d",&n);
for(i=1;i<=10;i++)
printf("%d\t",i*n);

}


Explain Program

Step :1

#include<stdio.h>

Standard Input/Output header file.

Step :2

void main()

 defines the main function which is the entry point of any C program.

Step :3

int n, i;

  1. n: to store the number entered by the user.
  2. i: loop control variable for the for loop.

Step :4

printf("Enter Any Number:");

Prints a message to the screen to the user to enter a number

Step :5

scanf("%d", &n);

  • input from the user and stores it in the variable n.
  • %d is used to read an integer.
  • &n means the address of n, because scanf needs to modify the variable.

Step :6

for(i = 1; i <= 10; i++)

  1. A for loop that runs from i = 1 to i = 10.
  1. Purpose: to generate and display the multiplication table of the number n

Step :7

 printf("%d\t", i * n);

  • In each iteration, prints i * n (which is a multiplication result).
  • \t is a tab character, used to separate the numbers with space.


Write  C Program  To Print  Multiplication Table  using For Loop

 Program Output 





Related Post :-