programming-examples/c/Basic/C Program to Print Diamond Pattern.c

42 lines
843 B
C
Raw Normal View History

2019-11-18 14:44:36 +01:00
/*
* C Program to Print Diamond Pattern
*/
#include <stdio.h>
int main()
{
int number, i, k, count = 1;
printf("Enter number of rows\n");
scanf("%d", &number);
count = number - 1;
for (k = 1; k <= number; k++)
{
for (i = 1; i <= count; i++)
printf(" ");
count--;
for (i = 1; i <= 2 * k - 1; i++)
printf("*");
printf("\n");
}
count = 1;
for (k = 1; k <= number - 1; k++)
{
for (i = 1; i <= count; i++)
printf(" ");
count++;
for (i = 1 ; i <= 2 *(number - k)- 1; i++)
printf("*");
printf("\n");
}
return 0;
}
/*
*
***
*****
*******
*********
*******
*****
***