Thursday 21 July 2016

Printing Octagon | C++ Program to Print Patterns

Printing Octagon | C++ Program to Print Patterns

Preview of Printing Octagon in C++


#include <iostream>
using namespace std;

int main()
{
     int side,line=1,star=1,space=1,no_of_spaces,no_of_stars;

     cout << "Enter length of the side of the Octagon: ";
     cin >> side;

     cout << "\n\n";

     no_of_spaces = side;
     no_of_stars = side;

     for (line = 1; line <= side; line++){

           for (space = 1; space<no_of_spaces; space++)
                cout << " ";

           for (star = 1; star <= no_of_stars; star++)
                cout << "*";

           no_of_spaces--;
           no_of_stars += 2;

           cout << endl;
     }

     no_of_stars -= 2;

     for (line = 1; line<side; line++){

           for (star = 1; star <= no_of_stars; star++)
                cout << "*";

           cout << endl;
     }

     no_of_spaces = 1;
     no_of_stars -= 2;

     for (line = 1; line<side; line++){

           for (space = 1; space <= no_of_spaces; space++)
                cout << " ";

           for (star = 1; star <= no_of_stars; star++)
                cout << "*";

           no_of_spaces++;
           no_of_stars -= 2;

           cout << endl;
     }

     cout << "\n\n";
     return 0;
}

2 comments

  1. All the contents you mentioned in post is too good and can be very useful. I will keep it in mind, thanks for sharing the information keep updating, looking forward for more posts.Thanks cheap 24x36 canvas print

    ReplyDelete
  2. When promoting the businesses, the most important part of the promotion is marketing and it always enjoys the number one position. Even the best businesses in the market cannot survive for long time without proper marketing. Therefore, the heart and soul of any business is marketing. Banner printing

    ReplyDelete

Recent Posts