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:
Half-Pyramid Using Number |
Important Topics:
1. For-loop
Code: You can download the image and also copy the code from below the image.
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
Output |
————————————————✖️———————————————
2. Print Half-Pyramid Using Alphabet in C Programming:
Half-Pyramid using Alphabet |
Important Topics:
1. For-loop
Code:
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:
output |
————————————————✖️———————————————
3. Print Inverted Half-Pyramid Using numbers in C Programming:
Inverted half-pyramid |
Important Topics:
1. For-loop
Code:
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:
Output |
————————————————✖️———————————————
4. Print Inverted Half-Pyramid Using '*' in C Programming:
Inverted half-pyramid using * |
Important Topics:
1. For-loop
Code:
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:
Output |
————————————————✖️———————————————
5. Print Full-Pyramid Using '*' in C Programming:
Full Pyramid |
Important Topics:
1. For-loop
Code:
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:
Output |
————————————————✖️———————————————
6. Print Full Inverted Pyramid in C-Programming:
Full Inverted Pyramid |
Important Topics:
1. For-loop
Code:
Code |
Floyd's Triangle |
Important Topics:
1. For-loop
Code:
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:
Output |
————————————————✖️———————————————
8. Print Pascal Triangle in C-Programming:
Pascal Triangle |
Important Topics:
1. For-loop
2. if-elseCode:
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:
Output |
————————————————✖️———————————————