Pattern Prgram in C Language with Answers. In this tutorial we have discussed pattern program questions with solution.We have shared program based on star pattern, number pattern, pyramid pattern and alphabet pattern. We have discussed both basics and advanced level program in this tutorial
In C Language patterns parograms are the best way to learn and practice loops. If anybody wants to improve their logical part then they must practice these programs. Following are the example of Star (*) pattern program in c Language.
*
**
***
****
*****
#include<stdio.h>
int main(){
int i,j,x;
printf("Enter value");
scanf("%d",&x);
for(i=1; i<=x;i++)
{
for(j=1;j<=i;j++){
printf("*");
}
printf("\n");
}
return 0;
}
*****
****
***
**
*
#include<stdio.h>
int main()
{
int i,j,x;
printf("Enter value");
scanf("%d",&x);
for(i=1; i<=x; i++)
{
for(j=i; j<=x; j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Following are the example of numeric pattern programs
1
22
333
4444
55555
#include<stdio.h>
int main()
{
int i,j,x;
printf("Enter value ");
scanf("%d",&x);
for(i=1; i<=x; i++)
{
for(j=1;j<=i; j++)
{
printf("%d",i);
}
printf("\n");
}
return 0;
}
1
12
123
1234
12345
#include<stdio.h>
int main()
{
int i,j,x;
printf("enter value ");
scanf("%d",&x);
for(i=1; i<=x;i++)
{
for(j=1;j<=i; j++)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}
1
23
345
4567
56789
#include<stdio.h>
int main()
{
int i,j;
for(i=1; i<=5; i++)
{
for(j=i;j<=(i*2)-1; j++)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}
1
21
321
4321
54321
#include<stdio.h>
int main()
{
int i,j,x;
printf("Enter value ");
scanf("%d",&x);
for(i=1; i<=x; i++)
{
for(j=i;j>=1;j--)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}
55555
4444
333
22
1
#include<stdio.h>
void main()
{
int i,j,x;
printf("Enter your number");
scanf("%d",&x);
for(i=x; i>=1; i--)
{
for(j=1; j<=i; j++)
{
printf("%d",i);
}
printf("\n");
}
}