31.05.2020
98
Write
  1. How To Write C Program
  2. How To Write C Program To Print Star Triangle
Active7 months ago

Print star triangle in C. Print Alphabet Pattern Program in C Print Number Series Program in C. Download Projects.

I need to print this triangle:

using a FOR and WHILE loop. I need help, I have already figured out the for loop version I just have to convert it to while loop but everything I try is not giving me the correct output! Any help is appreciated!

  • C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++.
  • Write a program in the c programming language to print an equilateral triangle of the asterisks or by using any other character. Make this program by using for loop statements. Below is the triangle we have to print as a output of the program.

My code so far:

user1118321Download How To Write C Program To Print Star Triangle
21.3k4 gold badges46 silver badges69 bronze badges
futurefuture

6 Answers

Bo PerssonBo Persson
80.1k17 gold badges129 silver badges187 bronze badges

I'll give you a hint (in the interest of making you do some figuring out yourself): You're forgetting to set j back to 1 after the inner loop.

As it is now, when j gets to be <= i once, it stays that way and the inner loop is never entered again.

Also, while it's not directly related to your question, make sure never to do j = j++ or i = i++; just do j++ and i++ (as Kshitij Mehta said in the comments). If you're interested in why, you can read this question and its answers.

Community
Seth CarnegieSeth Carnegie
62.1k15 gold badges154 silver badges226 bronze badges

I'll give you a hint as well: i = i++; doesn't do what you think it does.

JonJon

How To Write C Program

2,9121 gold badge15 silver badges25 bronze badges

I don't really know how to make it more succinct than this:

Bracket matching? Configurable Shortcuts Pro version only features:? Free pro apk downloads. Run Scripts in SL4A directly?

or as for loop, cutting down a line

If you don't mind some less efficient code:

sehesehe
287k35 gold badges363 silver badges488 bronze badges

How To Write C Program To Print Star Triangle

I can't see your triangle, but I think you need to set j to 1 before each loop on j:

Seth Carnegie
62.1k15 gold badges154 silver badges226 bronze badges
Nicolas GrebilleNicolas Grebille
סטנלי גרונן
1,8278 gold badges26 silver badges47 bronze badges
user10880661user10880661

Not the answer you're looking for? Browse other questions tagged c++while-loop or ask your own question.

sipoc.netlify.app – 2018