In this tutorial you will learn about the C Program to Print Star Pattern and its application with practical example.
C Program to Print Star Pattern
In this tutorial, we will learn to create a C program that will Create a Star pattern using C programming.
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- For loop in C Programming.
Create a Star pattern:-
The C language is a very powerful programming language. In C programming we can perform many operations with the help of codings. The c language is very easy to create any pattern. In this program, we will learn to create star-like patterns with the help of some code.
STEP 1: START
STEP 2: first declare the variables
STEP 3: then start the parent for loop
STEP 4: now make the child for loop
STEP 5: in this child loop print the blank spaces
STEP 6: now use another child loop to start drawing the <strong>Star </strong><strong>pattern</strong>
STEP 7: Now this for loop will also execute under the parent for loop
STEP 8: Print "\n" for changing the line before the increment of the main loop
STEP 9: increment of the main for loop
STEP 10: return the zero value for main function
To Create a Star pattern
// declaring the variables for the program
//Taking the size of the star user wanted to create
printf("Enter the size for the pattern :- \n");
if((j<=0.55*size*q && j>=(i+size)*w && j>=(size-i)*w)||(j>=(i+size)*w && j<=(i+size)*q && j<=(size-i)*q)||(j<=(size-i)*q && j>=(size-i)*w && j<=(i+size)*q))
//printing the pattern * at the places
//printing blank spaces
//Printing Line Break
The above program we have first initialized the required variable.
- i = it will hold the integer value to control parent for loop.
- j = it will hold the integer value to control child for loop.
- k = it will hold the integer value to control child for loop.
- size = it will hold the integer value for the number of rows of pattern.
Taking the size of the pattern.
Importing required header files.
Initializing the for loop size and number of rows.