Back to Blog
Example programs in c using do while6/13/2023 ![]() Printf("Sum of Integers from 1 to %d = %d", N, sum) Ībove program find sum of all integers from 1 to N, using do-while loop. ![]() This prints 1 on the screen and the value. ![]() Hence, the body of the while loop is executed. * Initializing loop control variable before do while loop */ Example 1: while loop When i 1, the test expression i < 5 is true. ![]() Do While loop iteration continues unless condition expression becomes false or while look gets terminated using break statement.Ĭ Program to find sum of integers from 1 to N using do while Loop.Step 2: To print the numbers, we need a counter, so here we have ‘i’ as a counter. If the value of condition expression is true then code block of do while loop(statements inside braces) will be executed again otherwise the loop will be terminated. Program to print numbers from 1 to n using a do-while loop: Step 1: First, we will take the input as far as we want to print the number. Then, the condition expression is tested. We use do.while loop when there is a need to check condition after execution of loop body. do.while is an exit controlled looping statement. Among three do.while loop is most distinct loop compared to others. First do while loop execute the codes inside body. C programming supports three types of looping statements for loop, while loop and do.while loop.
0 Comments
Read More
Leave a Reply. |