Description
Hello Guys...
There we will be solve the a problem in c programming language that how to print the star pyramid pattern. So this problem is solved today.
Now let's Code this program and solve this problem..
Code
/*
*
***
*****
*******
*********
*/
#include<stdio.h>
int main(){
int n;
printf("Enter the pyramid Size : ");
scanf("%d", &n);
// logic
for(int i=1; i<=n;i++){
for(int k=1; k<=n-i; k++){
printf(" ");
}
for(int j=1; j<=2*i-1; j++){
printf("*");
}
printf("\n");
}
return 0;
}
Step 1 : Initilized a variable that called n which store the value of the size of pyramid.
Step 2 : Print a message for user to enhance the readiblity.
Step 3 : Take the input with the help of scanf() library function.
Step 4 : Start for loop...
- Initilized a variable i , inilitally assigned the value 1 and goes to less than or equal to the given number by user.
- Start the another one for loop in the parent for loop. In this for loop we initilized a variable that called k, initially assigned the value 1 and goes to less than or equal to n-i. When this loop is execute then print the white space.
- Start the another second for loop in the parent for loop. In this for loop we initilized a variable that called j, initially assigned the value 1 and goes to less than or equal to (2*i-1). When this loop is execute then print the * .
- After print the white space and * print a new line.
Step 5 : Exit.
Thanks for reading this...
Recommended Posts
Even or Odd in C | How to check given number is odd or even
How to check the given number is odd or even in C programming language.
Factorial program in C | Factorial given number by user | Factorial
Hello Guys... Here we write a program to calculate the factorial a number given by user.
Factorial Using function | C programming language
Here we calculate the factorial using function in c programming language.
Prime number program in c | Calculate given number is prime or Not | prime number
What is prime number? and how to calculate the given number is prime or not |
Largest Number | C programming language
Hello guys.. Today we write a program how to find the largest number ( greatest number ) in array c programming language.