Question

In: Computer Science

A program is required to compare three numbers to see if any of them is equal...

A program is required to compare three numbers to see if any of them is equal to the product of the other two.

The program will take three integers, between 1 and 100 inclusive.

The program should output one of the following strings:

  • a = b * c
  • b = a * c
  • c = a * b
  • No number is the product of the others

You are given the following test data and an incomplete and error-filled program.

Test Number

Inputs

Expected Output
a b c
1 6 2 3 a = b * c
2 3 6 2 b = a * c
3 3 2 6 c = a * b
4 7 8 9 No number is product of the others

# Problem: Check if any of three numbers is product of others # Input: a as an integer from 1 to 100 # Input: b as an integer from 1 to 100 # Input: c as an integer from 1 to 100 a = 6 b = 2 c = 3 # Output: answer, a string if a == b + c answer = 'a = b * c' if b == a * c answer = 'b = a * c' if c == a + b : answer = 'c = a * b' if (a != b * c) and (b != a * c) and (c != a * b): answer = 'No number is product of others' print (answer)

Solutions

Expert Solution

Code:

#include <iostream>
using namespace std;
int main()
{
int a,b,c; //Variable declaration
cout<<"Enter 1st number a= ";
cin>>a; //take integer input from user as a
cout<<"Enter 2nd number b= ";
cin>>b; //take integer input from user as b
cout<<"Enter 3rd number c= ";
cin>>c; //take integer input from user as c
if((a>=1 && a<=100) && (b>=1 && b<=100) && (c>=1 && c<=100)) //check weather the numbers are between 1 to 100
{
if(a==b*c) //if a is the product of b and c
cout<<"Result: a=b*c"; //print result
else if(b==a*c)
cout<<"Result: b=a*c"; //if b is the product of a and c
else if(c==a*b)
cout<<"Result: c=a*b"; //if c is the product of a and b
else
cout<<"No number is product of others";
}
else
cout<<"Number is not between 1 and 100";
return 0;
}

Output:

code in Python

a = int(input("Enter first number a = "))
b = int(input("Enter first number b = "))
c = int(input("Enter first number c = "))

if a >= 1 and a <= 100 and b >= 1 and b <= 100 and c >= 1 and c <= 100:
   if a == b*c:
       print("Result a=b*c")
   elif b == a*c:
       print("Result b=a*c")
   elif c == a*b:
       print("Result c=a*b")
   else:
       print("No number is product of others")
else:
   print("Number is not between 1 and 100")


Related Solutions

Create this on Python Write a program that asks for three numbers. Check first to see...
Create this on Python Write a program that asks for three numbers. Check first to see that all numbers are different. If they’re not different, then exit the program. Otherwise, display the largest number of the three. Outputs: - Enter the first number: 4 - Enter the second number: 78 - Enter the third number: 8 (The largest number is 78.) Tasks - Complete the algorithm manually without using any built-in functions to find the largest number on list. -...
You are required to write an interactive JS program that prompts the user for three numbers...
You are required to write an interactive JS program that prompts the user for three numbers and then finds the sum, average, smallest, and the largest value of the numbers and prints the results labeling properly.
C++ Program: Write a program that prompts the user for two numbers and stores them in...
C++ Program: Write a program that prompts the user for two numbers and stores them in signed integers. The program should then add those two numbers together and store the result in a signed integer and display the result. Your program should then multiply them by each other and store the result in another integer and display the result. Then do the same but with dividing the first number by the second. Display an error message to the screen if...
Input from console 3 double numbers, compare these 3 numbers and display them from small to...
Input from console 3 double numbers, compare these 3 numbers and display them from small to great. In Java Please
There are three things wrong with this program. List each. print("This program takes three numbers and...
There are three things wrong with this program. List each. print("This program takes three numbers and returns the sum.") total = 0 for i in range(3):     x = input("Enter a number: ")     total = total + i print("The total is:", x)
Create a program that generates a file of random numbers, and then prints them in neat...
Create a program that generates a file of random numbers, and then prints them in neat fashion to another file, and also saves to that file the average and standard deviation of those numbers. I) First, you would need to generate a file of random numbers that consists of N random numbers (100 < N < 1000). Each random digit should be a real number (type double) between 0 and 50. This file and its digits would now serve as...
C++. Write a program that will read in id numbers and place them in an array.The...
C++. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please enter an...
in Java, write a program that takes an input of 4 numbers and splits them into...
in Java, write a program that takes an input of 4 numbers and splits them into 4 separate lines. EXAMPLE: so if input is 1994 the output should be 1 9 9 4
You are given the following questions, but not required to solve them for numbers. Instead, please...
You are given the following questions, but not required to solve them for numbers. Instead, please read them carefully and follow the instructions to complete each requirement. 1) Stoneycreek golf course is planning for the coming season. Investors would like to earn a 12% return on the company's $40 million of assets. The company primarily incurs fixed costs to groom the greens and fairways. Fixed costs are projected to be $20 million for the golfing season. About 500,000 golfers are...
Write a program that prints out all numbers, less than or equal to 10,000,000, that are...
Write a program that prints out all numbers, less than or equal to 10,000,000, that are evenly divisible by all numbers between 5 and 15 (inclusive). Do not use any libraries besides stdio.h. Need it in 10 minutes, please.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT