Diamond Star Pattern in C using For loop of Stars
ADVERTISEMENTS
Diamond star pattern in C using for loop of stars. In this article, you will learn how to print the diamond star pattern in c using for loop of stars.
Source Code
// Diamond Star Pattern in C using For loop of Stars
#include <stdio.h>
int main() {
int x, c, k, s = 1;
printf("-----Enter the number of rows-----\n");
scanf("%d", &x);
s = x - 1;
for (k = 1; k <= x; k++) {
for (c = 1; c <= s; c++)
printf(" ");
s--;
for (c = 1; c <= 2 * k - 1; c++)
printf("*");
printf("\n");
}
s = 1;
for (k = 1; k <= x - 1; k++) {
for (c = 1; c <= s; c++)
printf(" ");
s++;
for (c = 1 ; c <= 2 * (x - k) - 1; c++)
printf("*");
printf("\n");
}
return 0;
}
Output
-----Enter the number of rows-----
7
*
***
*****
*******
*********
***********
*************
***********
*********
*******
*****
***
*