Half Pyramid pattern program in c
In the below programs, we are going to see Half pyramid pattern programs in c, which consist of a program of star patterns in c, programs on numbers as well as on alphabets.
1. Half Pyramid star pattern program in c
#include <stdio.h>
int main()
{
int n;
printf("Enter the size of n\n");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
for(int j=0;j<=i;j++)
printf("*");
printf("\n");
}
return 0;
}
Output:
2. Inverted half pyramid star pattern program in c
#include <stdio.h>
int main()
{
int n;
printf("Enter the size of n\n");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
for(int j=0;j<n-i;j++)
printf("*");
printf("\n");
}
return 0;
}
Output:
3. Half pyramid number pattern program in c
#include <stdio.h>
int main()
{
int n;
printf("Enter the size of n\n");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
for(int j=0;j<=i;j++)
printf("%d",i+1);
printf("\n");
}
return 0;
}
Output:
4. Half pyramid number pattern program in c
#include <stdio.h>
int main()
{
int n;
printf("Enter the size of n\n");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
for(int j=0;j<=i;j++)
printf("%d",j+1);
printf("\n");
}
return 0;
}
Output:
5. Half pyramid hallow star pattern program in c
#include <stdio.h>
int main()
{
int n;
printf("Enter the size of n\n");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
for(int j=0;j<=i;j++)
{
if(j==0 || i==n-1 || i==j)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Output:
#include <stdio.h>
int main()
{
int n;
printf("Enter the size of n\n");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
for(int j=0;j<n-i;j++)
{
if(i==0 || j==0 || j==n-i-1)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Output:
7. half pyramid alphabet pattern program in c
#include <stdio.h>
int main()
{
int n;
char ch;
printf("Enter the size of n\n");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
ch='A';
for(int j=0;j<=i;j++)
printf("%c",ch++);
printf("\n");
}
return 0;
}
Output:
8. Half pyramid alphabet pattern program in c
#include <stdio.h>
int main()
{
int n;
char ch='A';
printf("Enter the size of n\n");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
for(int j=0;j<=i;j++)
printf("%c",ch);
printf("\n");
ch++;
}
return 0;
}
Output:
1 Comments
Your post is awesome and so informative for computer science students.
ReplyDeleteif you want news related content so pls visit here ->> Scorpio New Modal
Post a Comment