Learn about C Program to Print Half Diamond Star Pattern in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
C Program to Print Half Diamond Star Pattern
To print the half diamond pattern as below in C use the below C program. It takes number of rows as input and prints it.
* ** *** **** ***** **** *** ** *
Source code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n, star;
printf("Enter number of rows: ");
scanf("%d",&n);
for(int i=1; i< 2*n; i++)
{
if(i < n) star=i;
else star = abs(2*n-i);
for(int j=1; j<=star; j++)
printf("*");
printf("\n");
}
return 0;
}
Output:
Enter number of rows: 5 * ** *** **** ***** **** *** ** *
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
C program to print hollow diamond of numbers
C program to print hollow diamond of stars