Pattern 13: Triangle Star Pattern using for loop

Spread the love

Program to print below Triangle Star Pattern using for loop:

Write a C Program to print Triangle Star Pattern using the for loops.
The program should accept input from the user and display the pattern based on user input size.
Here is an expected output, When user input is 5.
Triangle-Star-Pattern-Program-in-c
Another Example of sample output, When the User Provided input as 10.

Note: This is one theSeries of pattern programs in C.

Triangle Star Pattern 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. for(i=-num;i<=num;i++)
  8. {
  9.       k=i;
  10. if(k<0)
  11. {
  12.          k = k * 1;
  13. }
  14. for (= 0; j <= num; ++j)
  15. {
  16. if (j<k)
  17. {
  18. printf(”  “);   // two spaces
  19. }
  20. else
  21. {
  22. printf(“* “);   // one star, one space.
  23. }
  24. }
  25. printf(n);
  26. }
  27. return 0;
  28. }

Output:

Related Programs :

More C programs:

C Tutorials with simple Examples:

Venkat

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...

Leave a Reply