Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 3.4, Problem 38STE
Explanation of Solution
Program:
//Include necessary header files
#include <iostream>
//Declare namespace
using namespace std;
//Define the main function
int main()
{
//Variable declaration
int n, m;
//Outer for loop to iterate n value
for(n=1;n<=10;n++)
//Inner or nested for loop to iterate m value
for(m=1;m>=1;m--)
//Print the result
cout<<nn&#...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
code in c++
Java program | nested loop
Please unroll the following loop three times. What is the benefit of loop unrolling?
for (i=0; i<42; i++) { a[i] = b[i] * i;}
Chapter 3 Solutions
Problem Solving with C++ (10th Edition)
Ch. 3.1 - Determine the value, true or false, of each of the...Ch. 3.1 - Name two kinds of statements in C++ that alter the...Ch. 3.1 - In college algebra we see numeric intervals given...Ch. 3.1 - Prob. 4STECh. 3.2 - What output will be produced by the following...Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - What would be the output in Self-Test Exercise 6...Ch. 3.2 - What would be the output in Self-Test Exercise 6...Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - What would be the output in Self-Test Exercise 9...
Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - Write a multiway if-else statement that classifies...Ch. 3.2 - Given the following declaration and output...Ch. 3.2 - Given the following declaration and output...Ch. 3.2 - What output will be produced by the following...Ch. 3.2 - What would be the output in Self-Test Exercise 15...Ch. 3.2 - What would be the output in Self-Test Exercise 15...Ch. 3.2 - What would be the output in Self-Test Exercise 15...Ch. 3.2 - Prob. 19STECh. 3.2 - Though we urge you not to program using this...Ch. 3.3 - Prob. 21STECh. 3.3 - Prob. 22STECh. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - Prob. 25STECh. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - Prob. 27STECh. 3.3 - For each of the following situations, tell which...Ch. 3.3 - Rewrite the following loops as for loops. a.int i...Ch. 3.3 - What is the output of this loop? Identify the...Ch. 3.3 - What is the output of this loop? Comment on the...Ch. 3.3 - What is the output of this loop? Comment on the...Ch. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - What is the output of the following (when embedded...Ch. 3.3 - What does a break statement do? Where is it legal...Ch. 3.4 - Write a loop that will write the word Hello to the...Ch. 3.4 - Write a loop that will read in a list of even...Ch. 3.4 - Prob. 38STECh. 3.4 - Prob. 39STECh. 3.4 - What is an off-by-one loop error?Ch. 3.4 - You have a fence that is to be 100 meters long....Ch. 3 - Write a program to score the paper-rock-scissor...Ch. 3 - Write a program to compute the interest due, total...Ch. 3 - Write an astrology program. The user types in a...Ch. 3 - Horoscope Signs of the same Element are most...Ch. 3 - Write a program that finds and prints all of the...Ch. 3 - Buoyancy is the ability of an object to float....Ch. 3 - Write a program that finds the temperature that is...Ch. 3 - Write a program that computes the cost of a...Ch. 3 - (This Project requires that you know some basic...Ch. 3 - Write a program that accepts a year written as a...Ch. 3 - Write a program that scores a blackjack hand. In...Ch. 3 - Interest on a loan is paid on a declining balance,...Ch. 3 - The Fibonacci numbers F are defined as follows. F...Ch. 3 - The value ex can be approximated by the sum 1 + x...Ch. 3 - Prob. 8PPCh. 3 - Prob. 9PPCh. 3 - Repeat Programming Project 13 from Chapter 2 but...Ch. 3 - The keypad on your oven is used to enter the...Ch. 3 - The game of 23 is a two-player game that begins...Ch. 3 - Holy digits Batman! The Riddler is planning his...Ch. 3 - You have an augmented reality game in which you...
Knowledge Booster
Similar questions
- Convert the following for loop definition to a do while loop: for(int j= 100; j > 0; j--) { if (j % 2 != 0) System.out.println (val); }arrow_forwardProvide trace table for the following loops: int s = 1; int n =1; do { s = s + n; n++; } while ( s < 10 * n);arrow_forwardThe following do...while loop rewritten as a for loop would be: int num = 5; do { System.out.print(num + " " ); num *= 3; //num = num * 3; } while (num <= 30); All of these are correct. int num = 5; for (num <= 30) { System.out.print(num + " "); num *= 3; } for (int num = 5; num <= 30) { System.out.print(num + " "); num *= 3; } for (int num = 5; num <= 30; num *= 3) { System.out.print(num + " " ); }arrow_forward
- Rewrite the following using a while-loop instead of a for-loop: int main(){ intk; int sum=0; for(k=10;k<50;k+=){ sum=sum+k; } cout<<"sum= " <<sum<<endl; system("pause"); return0;arrow_forwardLoops: Based on the following code segment: int val = 10; String s = String.format("%d", val - 5); while (val < 25) { s +=String.format(",%3d", val); val += 5; } System.out.println(s); Select the code using a for loop that produces identical output: String s = String.format("%d", val); for (int val = 10; val < 25; val + 5) { s += String.format(",%3d", val); } System.out.println(s); Strings = String.format("%d", 5); for (int val = 10; val <= 25; val += 5) { s +=String.format(",%3d", val); } System.out.println(s); String s = String.format("%d", 5); for (int val s += String.format(",%3d", val); } == 10; val < 25; val + 5) { System.out.println(s); None of these will produce the same output. String s = String.format("%d", 5); for (int val = 10, val < 25, val += 5) { s += String.format(",%3d", val); } System.out.println(s); Strings = String.format("%d", 5); for (int val = 10; val < 25; val += 5) { s +=String.format(",%3d", val); } System.out.println(s); String s = String.format("%d", 5); for…arrow_forwardthe total number of iterations of nested loops can be calculated by : O a. outer loop iterations / inner loop iterations O b. outer loop iterations + inner loop iterations O c. outer loop iterations - inner loop iterations O d. outer loop iterations * inner loop iterationsarrow_forward
- a and b are int variables containing values and a > b.Write a for loop that computes the sum of numbers from a to b (both inclusive) numbers with the last 2-digits 50.(Example: if a=700, b=128, then it will compute 650+550+450+....+150)Write only initialization of sum, and the for loop with its block, nothing else.arrow_forwardWhat the following code does? Replace the while loop with a for loop in the code: int s=0, i=2; while(i<=200) { s=s+i; i=i+2; }arrow_forwardWrite a for loop that prints from startNumber to finalNumber. Ex: startNumber = -3 and finalNumber = 1 outputs: -3 -2 -1 0 1arrow_forward
- Factorials The factorial of n (written n!) is the product of the integers between 1 and n. Thus 4! = 1*2*3*4 = 24. By definition, 0! = 1. Factorial is not defined for negative numbers. Write a program that asks the user for a non-negative integer and computes and prints the factorial of that integer. You'll need a while loop to do most of the work-this is a lot like computing a sum, but it's a product instead. And you'll need to think about what should happen if the user enters 0. 1. 2. Now modify your program so that it checks to see if the user entered a negative number. If so, the program should print a message saying that a nonnegative number is required and ask the user the enter another number. The program should keep doing this until the user enters a nonnegative number, after which it should compute the factorial of that number. Hint: you will need another while loop before the loop that computes the factorial. You should not need to change any of the code that computes the…arrow_forwardWhat are the differences between a while loop and a do-while loop? Convert the following while loop into a do-while loop. int sum = 0;int number;cin >> number; while (number != 0) {sum += number; cin >> number; }arrow_forwardot sum = 0 final int MAX ROWS 7, MAX COLS=5, int rows, columns for (rows 0, rowsarrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr