Wap using for loop in c

Since, 2 is also less than 10, the test expression is evaluated to true and the body of for loop is executed. Now, the sum will equal 3. Therefore, the loop terminates and next, the total sum is printed. It takes a lot of effort and cost to maintain Programiz. We would be grateful if you support us by either:. Disabling AdBlock on Programiz.

C program to find power of a number using for loop

We do not use intrusive ads. C Programming for Loop Loops are used in programming to repeat a specific block of code. After reading this tutorial, you will learn to create for loop in C programming. Table of Contents What is loop? There are three loops in C programming: The initialization statement is executed only once.

while loop in C

This process repeats until the test expression is false. The for loop is commonly used when the number of iterations is known. The value of i should also be added each time. It is never a good idea to update the value of i inside the for loop.

while Loop

The for loop index should only be used as a counter. In your case, changing the value of i inside the loop will cause all sorts of confusion. I have the following formula that works without loops. I discovered it while trying to find a formula for factorials:. Thank you for your interest in this question.

Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site the association bonus does not count. Would you like to answer one of these unanswered questions instead? Benjamin 16k 30 You have to add sum each time to sum as well. Eric Lopez 4 4. Giving the answer away to obvious homework problems is ultimately not helpful to the poster; try to help them learn next time.

Write A Program In C print 10 to 1 numbers using for loop

In the future, when giving help for homework try to guide the OP to the answer instead of providing it outright. This works perfect at least i was able to see what i did wrong now.

continue statement in C

Although the answer was given haha. Yeah that works so far but i need the sum of all those numbers it prints.. You can try: Jiri Kriz Jiri Kriz 8, 2 21 Polaris Polaris