Create a program that will accept two numbers and display their sum, product and quotient

Sign Up to our social questions and Answers Engine to ask questions, answer people's questions, and connect with other people.

Have an account? Sign In

Create a program that will accept two numbers and display their sum, product and quotient

Write a program that will display the sum, difference, product and quotient of two numbers #include <iostream.h> #include <conio.h> int main() {    int sum,diff,prod,div, x , y;    cout<<" This is a program that will compute the "<<endl;    cout<<"sum, difference,product and division of two numbers.\n";    cout<<" Please enter the first integer.\n";    cin>>x;    cout<<" Please enter the second integer.\n";    cin>>y;     sum = x+y;     diff = x-y;     prod = x*y;     div = x / y;    cout<<"The sum is: ";    cout<<sum<<endl;    cout<<"The difference is: ";    cout<<diff<<endl;                 cout<<"The product is: ";    cout<<prod<<endl;    cout<<"The division is: ";    cout<<div<<endl;    getch();    return 0; }

Last update on August 19 2022 21:50:34 (UTC/GMT +8 hours)

Write a Java program that accepts two integers and then prints the sum, the difference, the product, the average, the distance (the difference between integer), the maximum (the larger of the two integers), the minimum (smaller of the two integers).

Test Data Input 1st integer: 25

Input 2nd integer: 5

Create a program that will accept two numbers and display their sum, product and quotient

Sample Solution:

Java Code:

import java.util.Scanner; public class Exercise9 { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Input 1st integer: "); int firstInt = in.nextInt(); System.out.print("Input 2nd integer: "); int secondInt = in.nextInt(); System.out.printf("Sum of two integers: %d%n", firstInt + secondInt); System.out.printf("Difference of two integers: %d%n", firstInt - secondInt); System.out.printf("Product of two integers: %d%n", firstInt * secondInt); System.out.printf("Average of two integers: %.2f%n", (double) (firstInt + secondInt) / 2); System.out.printf("Distance of two integers: %d%n", Math.abs(firstInt - secondInt)); System.out.printf("Max integer: %d%n", Math.max(firstInt, secondInt)); System.out.printf("Min integer: %d%n", Math.min(firstInt, secondInt)); } }

Sample Output:

Input 1st integer: 25 Input 2nd integer: 5 Sum of two integers: 30 Difference of two integers: 20 Product of two integers: 125 Average of two integers: 15.00 Distance of two integers: 20 Max integer: 25 Min integer: 5

Flowchart:

Create a program that will accept two numbers and display their sum, product and quotient

Java Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a Java program that reads a number and display the square, cube, and fourth power.
Next: Write a Java program to break an integer into a sequence of individual digits.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Validity of the date line

If you need to get a date object from a regular string in Java, use this useful auxiliary class that will take care of all the complexities of validation and conversion.

Ref: https://bit.ly/2VUzXAT

I'm new to the language and all this overflow problems and integer types are getting on my nerves. here is what I have but when I run it I get,

-bash: syntax error near unexpected token `newline'

The code:

#include <stdio.h> int main(void) { int one, two, s, q, m; s = one+two q = one/two m = one*two printf("Enter first positive integer: "); scanf("%d", &one); printf("Enter second positive integer: "); scanf("%d", &two); printf("The addition of %d and %d is %d", one, two, s); printf("The integer division of %d divided by %d is %d", one, two, q); printf("the multiplication of %d and %d is %d", &one, &two, m); return 0; }

Thank you