Pattern 15: C Program to print Irregular polyhedron star pattern with out spaces.
Write a C program to print the following Irregular polyhedron star pattern :
In this Article, We are going to print the Irregular polyhedron star pattern using the for loops. We will two for loops Outer For loop and inner for loop. Outer for will helps us to print the Rows. And Inner for loop will helps us to print the columns
* * * * *
* * * *
* * *
* *
*
*
* *
* * *
* * * *
* * * * *
Seems like Above output is not displaying properly. Here is the expected output in Image Format.
Note: This program is the similar program to Pattern 14 but without the spaces in between two triangles.
Here I am using continue keyword, It will take the execution of the program to next iteration on other words it simply skips the execution of present iteration and goes to next iteration. So in pattern 14 program iteration 0 is causing spaces, So I am just skipping that iteration by using continue.
Irregular 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 30 31 32 33 34 35 36 |
#include<stdio.h> int main() { int i,j,k,num; printf("Enter any value : "); scanf("%d",&num); // Start with -num and continue till the num for(i=-num; i<=num; i++) { // If i==0, Skip the Iteration if(i==0) continue; k=i; if(k>0) { k = k * -1; } for (j = 0; j < num; ++j) { if (j < (k+num)) { printf(" "); } else { printf("* "); } } printf("\n"); } return 0; } |
Output :
Note: If you want spaces in between two triangles just delete continue statement in the loop, Please Refer to the following post for more details. “Polyhedron with 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 15: Polyhedron Star Pattern – 2 […]