Skip to main content

Butterfly Pattern

 /* @ToDo 

Butterfly Pattern
    *                                   *
    *   *                           *   *
    *   *   *                   *   *   *
    *   *   *   *           *   *   *   *
    *   *   *   *   *   *   *   *   *   *
    *   *   *   *           *   *   *   *
    *   *   *                   *   *   *
    *   *                           *   *
    *                                   *
*/


#include <iostream>
using namespace std;

int main(){
     #ifndef ONLINE_JUDGE
        freopen("../asset/input.txt","r",stdin);
        freopen("../asset/output.txt","w",stdout);
    #endif
    // Code here!!

    int ncin>>n;

    for(int i=1;i<=n;i++){
        for(int j=1;j<=2*n;j++){
            if(j<=i || j >(2*n)-i)
                cout<<"\t*";
            else cout<<"\t";
        }
        cout<<endl;
    }
    for(int i=1;i<=n;i++){
        for(int j=n-i;j>0;j--)
            cout<<"\t*";
        for(int j=2*i;j>0;j--)    
            cout<<"\t";
        for(int j=n-i;j>0;j--)
            cout<<"\t*";
        
        cout<<endl;
    }
    return 0;
}

Comments

Subscribe to Get's Answer by Email