C++ PROGRAMMING:FROM...(LL) >CUSTOM<
C++ PROGRAMMING:FROM...(LL) >CUSTOM<
8th Edition
ISBN: 9780357019528
Author: Malik
Publisher: CENGAGE C
Expert Solution & Answer
Book Icon
Chapter 5, Problem 40SA

Explanation of Solution

The output of the above segment using for loop is “value=479”.

Below is the code converted into while loop with same output “value=479”.

#include <iostream>

using namespace std;

int main()

{

   int i=0; //initialize the value of i here

   int value = 3;

   while(i<5) //while loop replacing for loop

   {

    value = value * (i + 1) + i;

    i++; // increment the value of i inside the loop

   }

   cout << “value = “ << value << endl;

   return 0;

}

Below is the code converted into do while loop with same output “value=479”...

Blurred answer
Students have asked these similar questions
JAVA CODE PLEASE Functions With No Parameters and Return Values Quiz by CodeChum Admin Create a function named banner that prints “CodyChum” with a newline. In the main function, write a program that accepts an integer input which would serve as an inclusive stopping point of a loop iteration that starts at the value of 1. If the number that loops through the range is divisible by either 2 or 3, then call the banner function, otherwise just print the number. Input 1. One line containing an integer Output First line is the integer user input. Succeeding multiple lines containing an integer or “CodyChum” 10 1 CodyChum CodyChum CodyChum 5 CodyChum 7 CodyChum CodyChum CodyChum
#include <iostream>using namespace std;int main(){int i = 1;i = i - 1;while (i){cout << "its a while loop";i++;}return 0;}
Write code that uses any type of loop. The code should continually ask for a user input and sums all user inputs that are divisible by 2. The loop should continue until the user enters a negative number. The code should output the sum a single time once user entry has completed. You may assume all libraries and namespaces have been previously written into the code, you are just writing everything that would go inside the main function (beyond the return 0:).
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning