Pattern #15

Example#1: C program to generate pattern 15

#include<stdio.h>
int main()
{
	int n,i,j,k;
	printf("Enter number of rows:");
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n-i;j++)
		{
			printf(" ");
		}
	    for(k=1;k<=i;k++)
	    {
	    	printf("* ");//need one space after "* "
		}
		printf("\n");
	}
	for(i=n-1;i>=1;i--)
	{
		for(j=1;j<=n-i;j++)
		{
			printf(" ");
		}
	    for(k=1;k<=i;k++)
	    {
	    	printf("* ");//need one space after "* "
		}
		printf("\n");
	}
	return 0;
}

Output:

Facebook Comments

Back to Top