Computer Science, asked by kashishbirkhania817, 8 months ago

2. WRITE A PROGRAM TO ACCEPT TWO NUMBERS AND DISPLAY THEIR :
► SUM
DIFFERENCE
MULTIPLICATION
PRODUCT​

Answers

Answered by manjusaba4388
1

Explanation:

Find two numbers with sum and product both same as N

Last Updated: 20-12-2018

Given an integer N, the task is to find two numbers a and b such that a * b = N and a + b = N. Print “NO” if no such numbers are possible.

Examples:

Input: N = 69

Output: a = 67.9851

b = 1.01493

Input: N = 1

Output: NO

Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach: If observed carefully, we are given with sum and product of roots of a quadratic equation.

If N2 – 4*N < 0 then only imaginary roots are possible for the equation, hence “NO” will be the answer. Else a and b will be:

a = ( N + sqrt( N2 – 4*N ) ) / 2

b = ( N – sqrt( N2 – 4*N ) ) / 2

Answered by anindyaadhikari13
7

Question:-

Write a program to accept two numbers and display their sum, difference, product.

Program:-

class Number

{

static void main(int a, int b)

{

System.out.println("Sum: "+(a+b));

System.out.println("Difference: "+(a-b));

System.out.println("Product: "-(a*b));

System.out.println("Quotient: "+(a/b));

}

}

Similar questions