Pattern 13: Triangle star pattern using for loop

Spread the love

Write a C Program to print below traingle pattern using for loop:

Note: This is one the Series of pattern programs in C.

Program :

  1. #include<stdio.h>
  2. int main()
  3. {
  4.    int i,j,k,num;
  5.    printf(“Enter any value : “);
  6.    scanf(“%d”,&num);
  7.  
  8.    for(i=-num;i<=num;i++)
  9.    {
  10.       k=i;
  11.       if(k<0)
  12.       {
  13.          k = k * 1;
  14.       }
  15.       for (= 0; j <= num; ++j)
  16.       {
  17.          if (j<k)
  18.          {
  19.             printf(”  “);   // two spaces
  20.          }
  21.          else
  22.          {
  23.             printf(“* “);   // one star, one space.
  24.          }
  25.       }
  26.       printf(n);
  27.    }
  28.    return 0;
  29. }

Output:

Related Programs :

More C programs:

C Tutorials with simple Examples:

Venkatesh Macha

Hi Guys, I am Venkatesh Macha. I am a programmer and an Open Source enthusiast, Presently working as a Software Engineer. Apart from that, I love to explore new technologies and things.

You may also like...

Leave a Reply