Printing number pattern examples using For Loop in C++


Example Program

Here is the simple program for printing number pattern using For Loop in C++.

Source Code Example : 1

#include<iostream>
using namespace std;
int main()
{
    int i,j,a;
    cout<<"\nEnter the value:";
    cin>>a;
    for(i=1;i<=a;i++)
    {
        cout<<"\n";
        for(j=1;j<=i;j++)
        {
            cout<<i;
        }
    }
    return 0;
}
To download raw file Click Here

Output

Enter the value:5
1
22
333
4444
55555

Source Code Example : 2

#include<iostream>
using namespace std;
int main()
{
    int i,j,a;
    cout<<"\nEnter the value:";
    cin>>a;
    for(i=1;i<=a;i++)
    {
        cout<<"\n";
        for(j=1;j<=i;j++)
        {
            cout<<j;
        }
    }
    return 0;
}
To download raw file Click Here

Output

Enter the value:5
1
12
123
1234
12345

Source Code Example : 3

#include<iostream>
using namespace std;
int main()
{
    int i,j,a,b=1;
    cout<<"\nEnter the value:";
    cin>>a;
    for(i=1;i<=a;i++)
    {
        cout<<"\n";
        for(j=1;j<=i;j++)
        {
            cout<<" "<<b;
            b++;
        }
    }
    return 0;
}
To download raw file Click Here

Output

Enter the value:5
 1
 2 3
 4 5 6
 7 8 9 10
 11 12 13 14 15

Source Code Example : 4

#include<iostream>
using namespace std;
int main()
{
    int i,j,a;
    cout<<"\nEnter the value:";
    cin>>a;
    for(i=1;i<=a;i++)
    {
        cout<<"\n";
        for(j=1;j<=i;j++)
        {
            cout<<(i-j+1);
        }
    }
    return 0;
}
To download raw file Click Here

Output

Enter the value:10
Enter the value:5
1
21
321
4321
54321

Source Code Example : 5

#include<iostream>
using namespace std;
int main()
{
    int i,j,a;
    cout<<"\nEnter the value:";
    cin>>a;
    for(i=1;i<=a;i++)
    {
        cout<<"\n";
        for(j=1;j<=(a-i);j++)
        {
            cout<<" ";
        }
        for(j=1;j<=i;j++)
        {
            cout<<j;
        }
    }
    return 0;
}
To download raw file Click Here

Output

Enter the value:5
    1
   12
  123
 1234
12345

Source Code Example : 6

#include<iostream>
using namespace std;
int main()
{
    int i,j,a;
    cout<<"\nEnter the value:";
    cin>>a;
    for(i=1;i<=a;i++)
    {
        cout<<"\n";
        for(j=a-i+1;j>0;j--)
        {
            cout<<j;
        }
    }
    return 0;
}
To download raw file Click Here

Output

Enter the value:5
54321
4321
321
21
1

Source Code Example : 7

#include<iostream>
using namespace std;
int main()
{
    int i,j,a;
    cout<<"\nEnter the value:";
    cin>>a;
    for(i=1;i<=a;i++)
    {
        cout<<"\n";
        for(j=1;j<=i;j++)
        {
            cout<<" ";
        }
        for(j=1;j<=(a-i+1);j++)
        {
            cout<<j;
        }
    }
    return 0;
}
To download raw file Click Here

Output

Enter the value:6
123456
  12345
   1234
    123
     12
      1
                    

Source Code Example : 8

#include<iostream>
using namespace std;
int main()
{
    int i,j,n;
    cout<<"\nEnter the value :";
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cout<<"\n";
        for(j=1;j<=(n-i);j++)
        {
            cout<<"  ";
        }
        for(j=1;j<=i;j++)
        {
            cout<<" "<<j;
        }
        for(j=1;j<i;j++)
        {
            cout<<" "<<(i-j);
        }
    }
    for(i=1;i<=n;i++)
    {
        cout<<"\n";
        for(j=1;j<=i;j++)
        {
            cout<<"  ";
        }
        for(j=1;j<(n-i);j++)
        {
            cout<<" "<<j;
        }
        for(j=(n-i);j>0;j--)
        {
            cout<<" "<<j;
        }
    }
    return 0;
}
To download raw file Click Here

Output

Enter the value :5
         1
       1 2 1
     1 2 3 2 1
   1 2 3 4 3 2 1
 1 2 3 4 5 4 3 2 1
   1 2 3 4 3 2 1
     1 2 3 2 1
       1 2 1
         1    

Basic Programs


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples



Learn All in Tamil © Designed & Developed By Tutor Joes