Basic Programs
If Else based Programs
Loop Based Programs
Array Based Programs
String Programs
Function Programs
Pointers Programs
Structure & File Handling Programs
Data Structure Programs
Loop based Programs
C Program to print different type patterns
1
1 2
1 2 3
1 2 3 4
#include<stdio.h>
#include<conio.h>
void main()
{
int n=0, i=0, j=0;
printf("enter the limit");
scanf("%d",&n);
for(i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
{
printf("%d ",j);
}
printf("\n");
}
} Output of the above program is as following.
4 3 2 1
4 3 2
4 3
4
#include<stdio.h>
#include<conio.h>
void main()
{
int n=0, i=0, j=0;
printf("enter the limit");
scanf("%d",&n);
for(i=1; i<=n; i++)
{
for(j=n; j>=i; j--)
{
printf("%d ", j);
}
printf("\n");
}
} Output of the above program is as following.
         *
      * *
   * * *
* * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int n=0, i=0, j=0;
printf("enter the limit");
scanf("%d",&n);
for(i=1; i<=n; i++)
{
//this loop is used to print spaces
for(j=n; j>i; j--)
{
printf(" ");
}
//this loop used to print the stars
for(j=1;j<=i;j++)
{
printf("* ");
}
printf("\n");
}
}
Output of the above program is as following.
1 1
2 2
3 3
4 4
5
4 4
3 3
2 2
1 1
#include<stdio.h>
#include<conio.h>
int main()
{
int i=1,limit=0,j=0,row=1,k=1,f=0,flag=0;
printf("enter the limit");
scanf("%d",&limit);
for(i=1; i<=((2*limit)-1); i++)
{
k=1;
flag=0;
for(j=1;j<=((2*limit)-1); j++)
{
if(k==row)
{
printf("%d",k);
}
else
{
printf(" ");
}
if(flag==0)
{
k++;
}
else
{
k--;
}
if(k==limit)
{
flag=1;
}
}
if(f==0)
{
row++;
}
else
{
row--;
}
if(row==limit)
{
f=1;
}
printf("\n");
}
} Output of the above program is as following.
Video/ C Introduction
Watch video in full size

Enquiry about Course