Welcome

Hi! This blog is for beginners of c++ and java .You can check and pick codes for your programming assignments. This will also help you to understand the concepts of these programming languages. Its all about programming.

Diagrams By loops(Final)

Thursday, May 19, 2011

#include <iostream.h>

int main() {
    int i=0;
    int j=0;

    //--- for printing 11 asterisks ---
    for (i=0; i<11; i++)
        cout << "*";

    cout << endl;

    //--- for printing 11 asterisks ---
    for (i=0; i<3; i++){
        for (j=0; j<11; j++){
            if (j==0 || j==10)
                cout << "*";
            else
                cout << " ";
        }   // end for loop - with j variable
    cout << endl;
    } // end for

    //--- for printing 11 asterisks ---
    for (int k=0; k < 5; k++){
        if(!(k%2)){
            for (i=0; i<11; i++)
                cout << "*";
            cout << endl;
        }                                 // end if

        //--- for printing spaces between asterisks
        else {
            for (j=0; j<11; j++){
                    if (j==0 || j==10)
                        cout << "*";
                    else
                        cout << " ";
             }                    // end for loop - j variable
          cout << endl;
        } // end else
    } // end for loop - k variable


return 0;
} // end main