Pattern 7: Angled ( inclined ) Pyramid Star pattern program in C Language

Introduction:

Write a C Program to print Angled pyramid pattern using stars. We are going to use the two for loops. One is Outer for loop for rows and Inner for loop is for columns.

The Program should accept an number as a Input and create a Angled Pyramid pattern.

Here is an Expected Output of the program, If the user Input is 5.

Angled-pyramid-star-pattern-in-c-programming

Write a C Program to print below pattern ( Angled Pyramid pattern ) :

*
* *
* * *
* * * *
* * * * *
* * * *
* * * 
* * 
*

 

Program Logic:

This is one the series of pattern programs in C. This program accept one integer from the user and prints above triangle pattern( It prints pattern depending upon the number, above pattern is for n=4). Here I am using only two for loops to create above pattern. First for loop is responsible for the number of rows. so it always starts with -n. The inner loop is for columns. I am using small logic(using variable ‘k’) to accomplish this pattern with only two loops.

 

Angled Pyramid Pattern Program :

 

  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int i,j,k,n;
  5.     printf(“Enter the Value for n : “);
  6.     scanf(“%d”,&n);
  7.  
  8.     for(i=-n;i<=n;i++) // Note that ‘i’ is starting from -n (negative n)
  9.     {
  10.         k=i;
  11.         if(k<0)
  12.             k= k*-1;
  13.  
  14.         for(j=0;j<=n;j++)
  15.         {
  16.             if(k<=j)
  17.                 printf(“* “);
  18.         }
  19.         printf(“\n);
  20.     }
  21.         return 0;
  22. }
 

Output:

 

Similar Star pattern programs:

More C programs:

C Tutorials with simple Examples:

 

Venkatesh

Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

You may also like...

1 Response

  1. Good Logic

Leave a Reply