Pattern Printing 1

3/17/2012 code-examplecpppattern-printing

# Summary

I will be sharing multiple patterns with a sequence starting from #1 to lets see how far it goes.

The pattern that I will be printing in the following code was asked during my exams. It will print numbers in the following way

# Screenshot

Pattern Printing #1

# Code

#include "iostream.h"
#include "conio.h"

void main()
{
	int i,j,k;
	clrscr();
	for(i=1; i <= 5; i++)
	{
		for(j=0; j < i; j++)
		{
			cout << (i+j) << " ";
		}
		for(k=(i+j)-2; k > (i-1); k--)
		{
			cout << k << " ";
		}
		cout << endl;
	}
	getch();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21