Example programs in c using do while11/7/2022 ![]() Please don’t forget to miss the semi-colon after the while condition. We just replaced the While loop with the Do While loop. Printf("\nAverage of the %d Numbers = %.2f",n, Average) Printf("\nSum of the %d Numbers = %d",n, Sum) ![]() Printf("\nPlease Enter the elements one by one\n") This prints 1 on the screen and the value. ![]() Hence, the body of the while loop is executed. Printf("\nPlease Enter How many Number you want?\n") Example 1: while loop When i 1, the test expression i < 5 is true. Using the For loop in C Programming, this program will calculate the sum, and later this C program will calculate the average. Next, it will ask the user to enter individual items up to a declared number. This C program allows the user to enter the number (n) he wishes to calculate the average and sum. C Program to find Sum and Average of n Number using For Loop A "0" indicates that the program has performed correctly any other number will mean that the program ran into an error.How to write a C Program to calculate the Sum and Average of N number using For Loop, While Loop and Do While Loop. The main difference between a do-while loop and while loop is in the do-while loop the condition is tested at the end of the loop body, i.e do-while loop is exit. Like while the do-while loop execution is also terminated on the basis of a test condition. This means that it will need an integer to be returned once the program is finished. Loops in C/C come into use when we need to repeatedly execute a block of statements. Note how the "main" function is an int function.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |