C++ Program to Print number Pattern


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

C++ Program to Print number Pattern

#include<iostream.h>
#include<conio.h>

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

Output

1
23
456
78910

C++ Program to Print number Pattern

#include<iostream.h>
#include<conio.h>

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

getch();
}

Output

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

Example

#include<iostream.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)
        cout<<" ";
      else
        cout<<k++;
    }
    cout<<"\n";
  }
getch();
}

Output

      1
   2 3 4
5 6 7 8 9

0 comments: