This blog serves as a place for me where I can occasionally dump bits of content from my brain. Feel free to browse.

Astericks Program Code – Lab #5

Change ROWS variable to the number of rows you want to print.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <iomanip> // for the setw() manipulator
 
using namespace std;
 
int main() {
 
	int ROWS = 4; // Yeah in capitals, just to make it look cool!
	for (int x=1; x < ROWS + 1; x++) {
		cout << setw (ROWS + 1 - x);
		for (int i=1; i <= x * 2 - 1; i++) cout << "*";
		cout << endl;
	}
 
	for (x=ROWS-1; x > 0; x--) {
		cout << setw (ROWS + 1 - x);
		for (int i=1; i <= x * 2 - 1; i++) cout << "*";
		cout << endl;
	}
 
	return 0;
	// This comment is self explanatory... no need to explain :)
}

Output:



2 Comments on “Astericks Program Code – Lab #5”

  1. 1 Usman said at 4:10 am on March 31st, 2011:

    aby yaar class me nahi bta sakta tha??

  2. 2 admin said at 10:42 am on March 31st, 2011:

    ye class se hi tu post kia tha maine yar… :)


Leave a Reply