Print Pattern #3 in C

Source Code

/*

*
**
***
**
*

*/

#include <stdio.h>
//#include <conio.h>

void main () {
	int i, j, n;
	//clrscr();

	do {
		printf("\nPlease enter an odd number: ");
		scanf("%d", &n);
	} while (n%2 == 0);

	for (i=1; i<=n; i++) {
		if (i<=(n/2+1)) {
			for (j=1; j<=i; j++) {
				printf("*");
			}
		} else {
			for (j=n/2+1; j>=(i-n/2); j--) {
				printf("*");
			}
		}
		printf("\n");
	}

	//getch();
}

Output

Please enter an odd number: 25
*
**
***
****
*****
******
*******
********
*********
**********
***********
************
*************
************
***********
**********
*********
********
*******
******
*****
****
***
**
*

Leave a Reply

Note: Your email address will not be published. Required fields are marked *