C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
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
Do in GO programming language  A. Write a program in Go that uses a for loop to print the numbers between 0 and 10 inclusive. B. Write a program in Go that includes a value returning function. The function should calculate the grade assigned based on a score entered. A = 90-100, B = 80-89, C = 70-79, D=60-69, and F below 60   C. Write a program in Go that calls a function that asks for someone’s name and prints “hello X” where X is the person’s name.
Given the following program segment: int first = 3; int second = 4; int j; for ( j = 1;  j <= first;  j++) {      cout << second * j  <<endl;     second= second + (j - 1); }   cout << endl; Your task is to write a while loop and a do ... while loop which will produce the same output.
1) Write a FUNCTION that asks the user to input a string.Unless the user inputs "END" or "end", a loop will execute wherein the user is asked to input a string. Each time the loop runs and the user input a string, the function does the following:+Print the number of letters in the string that the user inputs;+Print the number of digits in the string that the user inputs.When the user enters "END" or "end" the loop stops and the function prints the aggregate numbers of letters and digits that the user has entered from the beginning.Example:1st loop: a8K6H => 3 letters and 2 numbers2nd loop: THGF*T425 => 5 letters and 3 numbersAggragates: 8 letters and 5 numbers
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage