Print number Pattern in C


Prev Tutorial Next Tutorial

C Program to Print Patterns of numbers

In c language you can print any number Pattern. Here i will show you how to print all number Pattern in c language with explanation.

C Program to Print Patterns of numbers

#include<stdio.h>
#include<conio.h>

void main()
{
int i,j, k=1;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<i;j++)
{
printf("%d",k);
k++
}
printf("\n");
}
getch();
}

Output

1
23
456
78910

C Program to Print Patterns of numbers

#include<stdio.h>
#include<conio.h>

void main()
{
  int i, j;
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=i;j++)
        {
            printf("%d",i);
        }
        printf("\n");
    }

getch();
}

Output

1
2 2 
3 3 3
4 4 4 4
5 5 5 5 5

Print number Pattern in C

#include<stdio.h>
#include<conio.h>

void main()
{
  int i,j,k;
  k=1;
  for(i=1;i<=5;i+=2)
  {
    for(j=5;j>=1;j--)
    {
      if(j>i)
        printf(" ");
      else
        printf("%d ",k++);
    }
    printf("\n");
  }
getch();
}

Output

      1
   2 3 4
5 6 7 8 9

C Program to Print Patterns of numbers

#include<stdio.h>
#include<conio.h>

void main()
{
int i, j;
clrscr();
for(i=1;i<=7;i+=2)
{
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
for(i=5;i>=1;i-=2)
{
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
getch();
}

Output

1
123
12345
1234567
12345
123
1

Example

#include<stdio.h>
#include<conio.h>

void main()
{
int i, j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
printf("%d",i);
printf("\n");
}
getch();
}

Output

11111
22222
33333
44444
55555

Example

#include<stdio.h>
#include<conio.h>

void main()
{
int i, j;
clrscr();
for(i=5;i>=1;i--)
{
for(j=5;j>=1;j--)
{
if(j>i)
printf(" ");
else
printf("%d",j);
}
printf("\n");
}
getch();
}

Output

54321
 4321
  321
   21
    1

print number pattern

#include<stdio.h>
#include<conio.h>

void main()
{
int n, c, d, num = 1, space;
clrscr();
printf("Enter any number (1-10): ");
scanf("%d",&n);
space=n-1;
for(d=1; d<=n; d++)
{
num=d;
for(c=1; c<=space; c++)
printf(" ");
space--;
for(c=1; c<=d; c++)
{
printf("%d", num);
num++;
}
num--;
num--;
for(c=1; c<d; c++)
{
printf("%d", num);
num--;
}
printf("\n");
}
getch();
}

Output

Enter any number (1-10): 4
   1
  232
 34543
4567654

Prev Tutorial Next Tutorial

Advertisements




Facebook Likes

Advertisements