Follow This Blog For more... 😊

Zig-Zag Pattern in 3-line using C++.

Zig-Zag Pattern in 3-line using C++.

CODE:

    //Zig-Zag Pattern
    //
    //     *       *
    //   *   *   *   *
    // *       *       *
    //

    #include<iostream>
    using namespace std;
    main()
    {
        int i,j,n,k;
       
        cout<<"Enter the number:";cin>>n;
       
        for(i=1;i<=3;i++)
        {
            for(j=1;j<=n;j++)
            {
                if((i+j)%4==0||(i==2 && (i+j)%2==0))
                {
                    cout<<"* ";
                }
                else
                {
                    cout<<"  ";
                }  
            }
            cout<<endl;
        }
    }


OUTPUT:




Comments

Popular Posts