Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! ๐ ๐นLearn advanced coding techniques in C& C++ ๐นMaster Linux internals & shell scripting ๐นDeep dive into Data Structures & Algorithms ๐นExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) ๐นGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
Diamond pattern in C
๐ท C Program: Diamond Star Pattern
#include<stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
// Upper Half
for(int i=1; i<=num; i++)
{
for(int k=num; k>=i; k--)
{
printf(" ");
}
for(int j=i; j>=1; j--)
{
printf("* ");
}
printf("\n");
}
// Lower Half
for(int i=num; i>=1; i--)
{
for(int k=num; k>=i; k--)
{
printf(" ");
}
for(int j=1; j<=i; j++)
{
printf("* ");
}
printf("\n");
}
return 0;
}
๐ Explanation:
This C program prints a full diamond star pattern. It first constructs the top half of the diamond using an upright pyramid of stars with leading spaces for alignment. The bottom half is constructed using an inverted pyramid.
- The outer loops run for `num` lines each for the top and bottom halves.
- The inner loops handle spacing and star printing.
- Spacing ensures the stars are centered, forming a symmetric diamond shape.
๐ Sample Output:
Enter the number:
4
*
* *
* * *
* * * *
* * * *
* * *
* *
*
๐ท️ Keywords:
C star pattern, diamond pattern in C, full diamond program, half pyramid in C, inverted pyramid, star shape printing in C, C loop practice
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps

Comments
Post a Comment