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
C Pattern Program: Hourglass Star Shape
๐ท C Pattern Program: Hourglass Star Shape
#include <stdio.h>
int main()
{
int num;
printf("Enter the number: ");
scanf("%d", &num);
// Upper half
for (int i = 0; i < num; i++)
{
for (int j = 0; j < (num - i - 1); j++)
{
printf(" ");
}
printf("*\n");
}
// Lower half
for (int i = 1; i < num; i++)
{
for (int j = 0; j < i; j++)
{
printf(" ");
}
printf("*\n");
}
return 0;
}
๐ Explanation:
This C program prints a vertical hourglass-like star pattern using spaces and a single * per row.
๐น The first loop prints the upper half: decreasing spaces followed by a star.
๐น The second loop prints the lower half: increasing spaces followed by a star.
๐น Together, it creates a symmetrical hourglass shape centered around the vertical axis.
๐ Sample Output:
Enter the number: 5
*
*
*
*
*
*
*
*
*
๐ท️ Keywords:
C pattern printing, star pattern, diamond pattern, vertical hourglass, single star pattern, C loop pattern examples
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