Pattern 14 : C Program to print Irregular polyhedron star pattern
Write a C Program to print below Polyhedron Star Pattern using for loop:
The Polyhedron Star pattern program will take input size from the user, Depending upon the given size it will print the Output.
Here is an example, Where input size is 5.
Example 2:
When Input size is 3.
1 2 3 4 5 6 7 8 |
Enter any value : 3 * * * * * * * * * * * * |
Note:This is one theSeries of pattern programs in C.
Polyhedron Star Pattern Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include<stdio.h> int main() { int i,j,k,num; printf("Enter any value : "); scanf("%d",&num); for(i=-num; i<=num; i++) { k=i; if(k>0) { k = k * -1; } for (j = 0; j < num; ++j) { if (j < (k+num)) { printf(" "); // One Space Only } else { printf("* "); // One Star, One Space } } printf("\n"); } return 0; } |
Output:
Note : If you don’t want spaces in between two triangles just add one continue statement in the loop, Please Refer to the following post for more details. “Polyhedron without spaces“.
Related Programs :
- Basic star pattern program (The square pattern with stars).
- Triangle star pattern program.
- Triangle star pattern program with Spaces.
- Pyramid star pattern.
- Reverse Pyramid program.
- Diamond Star pattern program.
- star pattern program.
- K-Star pattern program.
- Empty Rhombus program.
- X-Star pattern program.
More C programs:
- Program to calculate Maximum of three numbers.
- What are Prime Number and C program to Check given number is Prime or Not
- Check given Number is Prime or not Using Square Root(sqrt) Function.(Efficient way)
- C Program to generate prime numbers between two numbers
- C Program to generate first N prime numbers.
- C program to Calculate percentage of student.
- C Program to check given year is the leap or not.
- C Program to convert Temperature.
- C program to understand type conversation.
- Finding Largest of two numbers using the conditional operator in C.
- C program to calculate the simple Interest,
- C program to understand Size of Operator.
- 200+ C Programs.
C Tutorials with simple Examples:
- Arithmetic Operators with Examples.
- Arithmetic operators priority and it’s Associativity.
- Modulus Operator and Hidden Concepts of Modulus Operator.
- Precedence Table or Operators Priority Table.
- Assignment Operator, Usage, Examples
- Increment Operator and Different types of Increment operators Usage with Examples.
- Decrement Operator and Different types of Decrement operators with Examples.
- Logical or Boolean Operators.
1 Response
[…] Pattern 14: Polyhedron Star Pattern […]