C pattern Programs

1.Display the pattern:
1
1 2
1 2 3
1 2 3 4

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf("Enter the number nth number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("%n");
}
getch();
}
OUTPUT:
Enter the number nth number:4
1
1 2
1 2 3
1 2 3 4

2.Display the pattern:
@ @ @ @
  @ @ @
    @ @
      @

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
for(i=5;i>=i;i--)
{
for(j=1;j<=5-i;j++)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("@");
}
printf("/n");
}
getch();
}
OUTPUT:
@ @ @ @
  @ @ @
    @ @
      @


3.Display the following pattern:
          *
         ** 
        ***
       ****
      *****
     ******
      *****
       ****
        ***
         **
          *

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf("Enter the number of * in the centre line:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-1;j++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
for(i=n-1;i>=1;i--)
{
for(j=1;j<=n-i;j++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
OUTPUT:
Enter the number of * in the centre line:6
          *
         ** 
        ***
       ****
      *****
     ******
      *****
       ****
        ***
         **
          *



4.Display the pattern:
1
12
123
1234
12345
123456

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf("Enter the number of lines:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
OUTPUT:
Enter the number of lines:6
1
12
123
1234
12345
123456


5.Display the pattern:
A
B C
D E F
G H I J
K L M N O
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,k;
clrscr();
printf("Enter the number of lines:");
scanf("%d",&n);
for(i=1;k=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%c",64+k++);
}
printf("\n");
}
getch();
}

OUTPUT:
Enter the number of lines:
A
B C
D E F
G H I J
K L M N O

Translate »