My Youtube Channel

Please Subscribe

Flag of Nepal

Built in OpenGL

Word Cloud in Python

With masked image

Showing posts with label Pattern. Show all posts
Showing posts with label Pattern. Show all posts

Friday, December 7, 2018

Draw the pattern.









Program code (in c++)

#include<iostream>
using namespace std;

int main()
{
    int a[10]={0,1,2,3,4,5,6,7,8,9};
    for(int i=1;i<=5;i++)
    {
        for(int p=1;p<=5-i;p++)
        {
            cout<<" ";
        }

        int n=1;
        int k=i;

        do{
            if(n<=i)
            {

                cout<<a[k];
                k++;

            }
            else{
                k--;

                cout<<a[k-1];
            }




            n++;
        }while(n<=(2*i-1));
        cout<<"\n";
    }

    return 0;


}