Concept explainers
Each of the
A) int num1 = 0, num2 = 10, result;
num1++;
result = ++(num1 + num2);
cout << num1 << " " << num2 << " " << result;
B) // This code should add two user-entered numbers,
int num1, num2;
char again;
while ((again == 'y') || (again == 'Y'))
cout << "Enter two numbers: ";
cin >> num1 >> num2;
cout << "Their sum is << (num1 + num2) << endl ;
cout << "Do you want to do this again? ";
cin >> again;
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Starting Out with C++: Early Objects (9th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: Early Objects (6th Edition)
C Programming Language
Absolute Java (6th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
- Q1: Write a program that reads 10 numbers and then finds the largest number and prints it and finds the smallest number and eyarrow_forwardCoin Toss Write a function named coinToss that simulates the tossing of a coin. When you call the function, it should generate a random number in the range of 1 through 2. If the random number is 1, the function should display "heads". If the random number is 2, the function should display "tails". Demonstrate the function in a program that sks the user how many times the coin should be tossed and the coin then simulates the tossing of the coin that number of times.arrow_forwarddef area(side1, side2): return side1 * side2s1 = 12s2 = 6 Identify the statements that correctly call the area function. Select ALL that apply. Question options: A print(f'The area is {area(s1,s2)}') B answer = area(s1,s2) C result = area(side1,side2) D area(s1,s2)arrow_forward
- PYTHON HOMEWORK QUESTION def area(side1, side2): return side1 * side2 s1 = 12s2 = 6 Select all statements that correctly call the area function. A. answer = area(s1,s2)B. print(f'The area is {area(s1,s2)}')C. area(s1,s2)D. result = area(side1,side2)arrow_forwardThe program segment has errors. Find as many as you can. // This code should average a set of numbers. int numCount, total;double average; cout << "How many numbers do you want to average? "; cin >> numCount;for (int count = 0; count < numCount; count++) {int num;cout << "Enter a number: "; cin >> num;total += num; count++;}average = total / numCount;cout << "The average is << average << end1;arrow_forwardin this code, the integer on each line shows the line number that is not part of code: write line where a call to sum takes place: ____ 1 public static int sum(int x, int y){ 2 int z = x +y; 3 return z; 4 } 5 public static void main(String[] args){ 6 … 7 sum(a+2, b); 8 … 9 }arrow_forward
- The program in the Programming Example: Fibonacci Number does not check whether the first number entered by the user is less than or equal to the second number and whether both the numbers are non-negative. Also, the program does not check whether the user entered a valid value for the position of the desired number in the Fibonacci sequence. Rewrite that program so that it checks for these things.arrow_forward(Statistics) This is the formula for the standard normal deviate, z, used in statistical applications: z=(X)/ X is a single value. refers to an average value. refers to a standard deviation. Using this formula, you need to write a program that calculates and displays the value of the standard normal deviate when X=85.3,=80,and=4. a. For this programming problem, how many outputs are required? b. How many inputs does this problem have? c. Determine a formula for converting input items into output items. d. Test the formula written for Exercise 7c, using the data given in the problem.arrow_forward(Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning