Print Pattern #1 in C

Source Code

/*
   1
  12
 123
1234
*/

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

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

	//printf("\nPlease enter a number: ");
	//scanf("%d", &n)

	for (i=1; i<=n; i++) {

		for (j=n-1; j>=i; j--) {
			printf(" ");
		}

		for (j=1; j<=i; j++) {
			printf("%d", j);
		}

		printf("\n");
	}

	//getch();
}

Output

   1
  12
 123
1234

Leave a Reply

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