17/07/2019

Design Different types of Pattern in C Programming, Pyramid, Pascal, Floyd's etc

Design Different types of Pattern in C Programming, Pyramid, Pascal, Floyd's, etc: 

We draw some pattern using C-Language here using control statement.

1. Print Half-Pyramid Using Number in C Programming:

Print Half-Pyramid Using Number in C
Half-Pyramid Using Number

Important Topics:

1. For-loop

Code: You can download the image and also copy the code from below the image.

Print Half-Pyramid Using Number in C
Code

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

Output: Output is given below

Print Half-Pyramid Using Number in C
Output

               ————————————————✖️———————————————

2. Print Half-Pyramid Using Alphabet in C Programming:

 Print Half-Pyramid Using Alphabet in C Programming
Half-Pyramid using Alphabet

Important Topics:

1. For-loop

Code:

 Print Half-Pyramid Using Alphabet in C Programming
Code


#include <stdio.h>
int main()
{
    int i,j;
    char input,alphabet = 'A';
    printf("Enter the uppercase character you want to print in last row: ");
    scanf("%c",&input);
    for(i=1;i<=(input-'A'+1);++i)
    {
        for(j=1;j<=i;++j)
        {
            printf("%c ",alphabet);
        }
        ++alphabet;
        printf("\n");
    }
    return 0;
}

Output:

 Print Half-Pyramid Using Alphabet in C Programming
output

                  ————————————————✖️———————————————



3. Print Inverted Half-Pyramid Using numbers in C Programming:

Print Inverted Half-Pyramid Using numbers in C Programming
Inverted half-pyramid

Important Topics:


1. For-loop

Code:

Print Inverted Half-Pyramid Using numbers in C Programming
code

#include<stdio.h>
int main()
{
  int j,i,n;
  printf("How many Rows?");
  scanf("%d",&n);
for(i=n;i>0;i--)
  {
    for(j=1;j<=i;j++)
    printf("%d ",j);
    printf("\n");
  }
  printf("\n");
}

Output: 

Print Inverted Half-Pyramid Using numbers in C Programming
Output

                  ————————————————✖️———————————————


4. Print Inverted Half-Pyramid Using '*' in C Programming:

Print Inverted Half-Pyramid Using '*' in C Programming
Inverted half-pyramid using *




Important Topics:

1. For-loop


Code:

Print Inverted Half-Pyramid Using '*' in C Programming
Code

#include<stdio.h>
int main()
{
  int j,i,n;
  printf("How many Rows?");
  scanf("%d",&n);
for(i=n;i>0;i--)
  {
    for(j=i;j>0;j--)
    printf("* ");
    printf("\n");
  }
  printf("\n");
}

Output:

Print Inverted Half-Pyramid Using '*' in C Programming
Output


                 ————————————————✖️———————————————



5. Print Full-Pyramid Using '*' in C Programming:

Print Full-Pyramid Using '*' in C Programming
Full Pyramid

Important Topics:

1. For-loop


Code:

Print Full-Pyramid Using '*' in C Programming
Code



#include<stdio.h>
int main()
{
  int j,i,n,k=0;
  printf("How many Rows?");
  scanf("%d",&n);
for(i=1;i<=n;i++,k=0)
  {
    for(j=1;j<=n-i;j++)
    printf(" ");
    while(k!=2*i-1)
    {
    printf("*");
    ++k;
    }
    printf("\n");
  }
}

Output:


Print Full-Pyramid Using '*' in C Programming
Output




                ————————————————✖️———————————————


6. Print Full Inverted Pyramid in C-Programming:


Print Full Inverted Pyramid in C-Programming
Full Inverted Pyramid

Important Topics:

1. For-loop

Code:

Print Full Inverted Pyramid in C-Programming
Code

#include<stdio.h>
int main()
{
  int j,i,n;
  printf("How many Rows?");
  scanf("%d",&n);
for(i=n;i>0;i--)
  {
    for(j=i;j>0;j--)
    printf("* ");
    printf("\n");
  }
  printf("\n");
}

Output: 

Print Full Inverted Pyramid in C-Programming
Output

————————————————✖️———————————————


7. Print Floyd's Triangle in C-Programming:

Print Floyd's Triangle in C-Programming
Floyd's Triangle

Important Topics:

1. For-loop

Code:

Print Floyd's Triangle in C-Programming
Code

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

Output: 

Print Floyd's Triangle in C-Programming
Output

            ————————————————✖️———————————————


8. Print Pascal Triangle in C-Programming:


Print Pascal Triangle in C-Programming
Pascal Triangle

Important Topics:

1. For-loop
2. if-else

Code:

Print Pascal Triangle in C-Programming
Code
#include<stdio.h>
int main()
{
int i,j,n,space,k;
printf("Enter the rows numbers:");
scanf("%d",&n);
for(i=0; i<n; i++)
    {
        for(space=1; space <=n-i; space++)
            printf("  ");
        for(j=0; j <= i; j++)
        {
            if (j==0 || i==0)
                k = 1;
            else
                k = k*(i-j+1)/j;
            printf("%4d", k);
        }
        printf("\n");
    }
    return 0;
}

Output: 

Print Pascal Triangle in C-Programming
Output
————————————————✖️———————————————

2 comments: