write a c++ program to print octagon
Answers
Answered by
0
#include <iostream>
using namespace std;
int main()
{
intside,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;
}
using namespace std;
int main()
{
intside,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;
}
Similar questions
Social Sciences,
7 months ago
Math,
7 months ago
Social Sciences,
7 months ago
Hindi,
1 year ago
Chinese,
1 year ago
CBSE BOARD XII,
1 year ago