C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Question
error_outline
This textbook solution is under construction.
Students have asked these similar questions
Rewrite the following as a for loop. int i = 0, value = 0;while (i <= 20){if (i % 2 == 0 && i <= 10)value = value + i * i;else if (i % 2 == 0 && i > 10)
value = value + i;elsevalue = value - i;i = i + 1;}cout << "value = " << value << endl;What is the output of this loop?
in java
String inputWord is read from input. Write a while loop that iterates until inputWord is equal to "Finale". In each iteration of the loop:
Read integer clothingNumber from input.
If clothingNumber is less than 30, output the value of inputWord, followed by ": low on stock" and a newline.
Otherwise, output the value of inputWord, followed by ": well stocked" and a newline.
Read string inputWord from input.
Click here for example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.util.Scanner;
public class PairedDataProcessing {
publicstaticvoidmain(String[] args) {
Scannerscnr=newScanner(System.in);
StringinputWord;
intclothingNumber;
inputWord=scnr.next();
/* Your code goes here */
}
}
A square is divided into four smaller regions as shown in (a). If you throw a dart into the square one million times, what is the probability for the dart to fall into an odd-numbered region? Write a program to simulate the process and display the result.
Knowledge Booster
Similar questions
- Write a program that prints all letters that occur a single time in a string. For example, if the string is Mississippi, print M, and if it is Missouri, print Mour. Use nested loops to solve this problem. CAN NOT EDIT ANY CODE OUTSIDE OF THE /* Your code goes here */arrow_forwardThe for loop in (a) is converted into the while loop in (b). What is wrong? Correct it. (java language) (a) int sum = 0; for (int i = 0; i < 4; i++) { if (i % 3 == 0) continue; sum += i; } (b) int i = 0, sum = 0; while (i < 4) { if (i % 3 == 0) continue; sum += i; i++; }arrow_forwardWrite a program that receives student's marks (8 marks) and evaluates the average: use conditions or loops If 50<=average<60 print "poor". If 60<=average<70 print "medium". If 70<=average<80 print "good". If 80<=average<90 print "very good". If 90<=average<=100 print "excellent". Otherwise, print "failarrow_forward
- What is the result of the following code? int xNum T 0; int yNum = 0; do { xNum = xNum+yNum; yNum += 1; cout << "xNum: } while (xNum > 2); << xNum; O a.xNum: 2 is printed O b. no output, the loop is never executed O c. xNum: 0 is printed O d. endless looparrow_forwardLoops, C++ Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 5 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 10 the output is: -15 -10 -5 0 5 10 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. For coding simplicity, output a space after every integer, including the last.arrow_forwardJAVA: Replace the for loop below with a code using the "While" loop: int s = 0; int c = 0; boolean valid = true; for(int i = 4; i <= 20 || valid; i = i+2) { if(i%4 != 0) { s = s + i; c++; } if(i > 20) { valid = false; } } System.out.println(s / c);arrow_forward
- What is the total number of iterations in the following loop ? for(int i=0; i<9; i+=2); a 0 b 5 c 4 d 9arrow_forwardwrite this in pseudocode #4 – In pseudocode, write a for-loop that decreases from 100 to 2 by 2s. Inside the loop, print the value of the loop variable unless the value is from 60 to 80 (inclusive). Use only 1 if-statement. Do NOT write Python code! Write your answer below: #5 – Review the decision structure given below. If myAnswer > 20 Then myAnswer = myAnswer - 25Else If myAnswer <= 5 Then If myAnswer < 0 Then myAnswer = 10 If myAnswer < 3 Then myAnswer += 10 Else myAnswer += 1Else myAnswer = 9 If myAnswer < 10 ThenmyAnswer += 1 Display myAnswer What are the results displayed when the decision structure above executes for each given value below:If myAnswer = 6 then myAnswer = myAnswer = 15 then myAnswer = myAnswer = 30 then myAnswer = myAnswer = 2 then myAnswer = myAnswer = -1 then myAnswer = #6 – 2-dimensional arrays can be thought of as containing rows…arrow_forwardHarlan A. Brothers and John A. Knox discovered that as the value of x gets larger, the value of the expression gets closer and closer to e. Write a program that evaluates this expression for x = 1, 2, 3, and so on until the absolute difference between the expression’s value and the value of e calculated by the library function (exp) is less than 0.000001. Display the value of x that causes your loop to exit along with both the final approximation of e and the value of e calculated by the (exp) function. Show seven decimal places. IN C PROGRAMMING LANGUAGE PLEASE AND COMMENT EVERY STEP OF ITarrow_forward
- Write a program that asks the user for a number of integer test scores. It then has the user enter that number of scores and computes the average. Ex: If the input is: 5 95 90 82 88 87 the output is: Your test average is: 88.4 You can assume that the first number is greater than 0. Hint: Use a loop to calculate the sum. When you are done with the loop, calculate the average. pythonarrow_forwardJAVA program Write a while loop that prints all the even numbers from 1 to 100 (inclusive). and another while loop to print all the odd numbers from 1 to 100 (inclusive).arrow_forwardAll the loops below are meant to do the same thing, except... Select one: a. int index = 0; do{ if(numbers[index]%2 == 1) System.out.println(numbers[index]+" is an odd number."); index++;}while(index < numbers.length); b. for(int a=0 ;a < numbers.length; a +=2){ System.out.println(numbers[a]+" is an odd number.") } c. for(int num:numbers){ if(num%2 == 1) System.out.println(num+" is an odd number.") } d. int index = 0; while(index < numbers.length){ if(numbers[index]%2 == 1) System.out.println(numbers[index]+" is an odd number."); index++; } CLEAR MY CHOICEarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr