Question

In: Computer Science

C programming. Explain by taking a programming example how do while loop is different from while...

C programming.

Explain by taking a programming example how do while loop is different from while loop?

Solutions

Expert Solution

While Loop Example

Here is a simple example of how a while loop works.This program prints numbers from 1 to 10 without actually using the ten printf statements but a while loop.

Here, the “\n” in the printf call is used to move to the next line.

Its output should look something like this-

DO-WHILE LOOP

Do-While Loop Example

Here is a simple example to find the sum of 1 to 10 using the do-while loop.

Its output should be something like this-

Difference Between while and do while loop

While Loop

DO WHILE LOOP


Related Solutions

C programming What is an array? Explain by taking an example that how can we take...
C programming What is an array? Explain by taking an example that how can we take input and output in 1D array?
This is for C++ You must use either a FOR, WHILE, or DO-WHILE loop in your...
This is for C++ You must use either a FOR, WHILE, or DO-WHILE loop in your solution for this problem. Write a quick main console program to output the following checker pattern to the console: #_#_#_#_# _#_#_#_#_ #_#_#_#_# _#_#_#_#_ #_#_#_#_#
Do the following lab by while or Do-while loop. question: Write a c++ program that asks...
Do the following lab by while or Do-while loop. question: Write a c++ program that asks students to enter 3 valid grades and then calculate the average and print it. if the user enters the invalid grade you should print the error message and get the new grade. Hint1: each time your program ask the following question: "Do you want to calculate another average?" and if the answer to this question is "Y" or "y" then you should continue. Hint2:...
Java Programming - please read the description I need this description. Inside a do/ while loop...
Java Programming - please read the description I need this description. Inside a do/ while loop (while choice !='x') , create a method call that calls a switch menu with 3 cases for variable choice and X for exit application.(this is a user input) Each case calls other methods. One of those methods asks for user input float numbers to calculate addition. And the result return to another method that displays the result. Thanks for your help! Thanks for asking....
C language and it has to be a while loop or a for loop. Use simple...
C language and it has to be a while loop or a for loop. Use simple short comments to walk through your code. Use indentations to make your code visibly clear and easy to follow. Make the output display of your program visually appealing. There is 10 points deduction for not following proper submission structure. An integer n is divisible by 9 if the sum of its digits is divisible by 9. Develop a program that: Would read an input...
Write a program in C++ coding that utilizes a DO-WHILE loop to redisplay a menu to...
Write a program in C++ coding that utilizes a DO-WHILE loop to redisplay a menu to the user. Ask the user to input their favorite SuperHero and display a positive or funny comment about the chosen SuperHero. If RBG is chosen, display "You can't spell TRUTH without RUTH." Utilize a Do-While Loop to redisplay the menu to the user after item 1, 2 or 3 is executed. If item 4 is chosen, end the program. If the user chooses 4,...
Modify the previous program to use the Do-While Loop instead of the While Loop. This version...
Modify the previous program to use the Do-While Loop instead of the While Loop. This version of the program will ask the user if they wish to enter another name and accept a Y or N answer. Remove the "exit" requirement from before. Output: Enter the full name of a person that can serve as a reference: [user types: Bob Smith] Bob Smith is reference #1 Would you like to enter another name (Y or N)? [user types: y] Enter...
write an operational semantic for a while loop in c++
write an operational semantic for a while loop in c++
Problem: Construct a C program that will make use of user-defined functions, the do/while loop, the...
Problem: Construct a C program that will make use of user-defined functions, the do/while loop, the for loop, and selection. Using a do/while loop, your program will ask/prompt the user to enter in a positive value representing the number of values they wish to have processed by the program or a value to quit/exit. If the user enters a 0 or a negative number the program should exit with a message to the user indicating they chose to exit. If...
Sentinel While Loop Lab Convert Lab 11 from a counter controlled WHILE loop to a sentinel...
Sentinel While Loop Lab Convert Lab 11 from a counter controlled WHILE loop to a sentinel WHILE loop. Do the following: Prompts the user to enter a grade or a -1 to quit. IF the user entered a -1 THEN Display a message that the User is done entering grades ELSE Count each grade as it is entered. Compute a running total of the grades entered. END IF After the user enters the sentinel of -1, calculate the average of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT