C Program to draw Diamond Pattern

Sample Input 1 :

5

Sample Output 1 :

    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#include<stdio.h> int main() { //write your code here }

Program or Solution

				
			
					
#include<stdio.h>
#include<math.h>
int main()
{
	int i,j,k,n,step=1;
	printf("enter row size:");
	scanf("%d",&n);
	for(i=1;i<=2*n-1;i++)
	{

		for(k=1;k<=abs(n-i);k++)
		{
			printf(" ");
		}
		for(j=1;j<=step;j++)
		{
			printf("*");
		}
		

		if(i<n)
		{
			step+=2;
		}
		else
		{	
			step-=2;
		}
		printf("\n");
	}
	return 0;
}
			
				
			

Program Explanation

Refer Video Tutorial

Comments