In: Computer Science
write a program that evaluates the following arithmetic expression: ((A+B)/C)*((D-A)+E). Assign test values to the variables and display the resulting value.
CPP code :
#include <iostream>
using namespace std;
int main() {
float A,B,C,D,E,f,g,h;
cout << "enter the value of A: " << endl;
cin >> A;
cout << "enter the value of B: " << endl;
cin >> B;
cout << "enter the value of C: " << endl;
cin >> C;
cout << "enter the value of D: " << endl;
cin >> D;
cout << "enter the value of E: " << endl;
cin >> E;
f=(A+B)/C;
g=(D-A)+E;
h=f*g;
cout <<"value of the arithmatic expression (A+B)/C)*((D-A)+E)
is:" << h;
}
Output
Java code:
import java.util.Scanner; // scanner library to take input from
user
public class Arithmaticoperation // class
{
public static void main(String args[]) //main method
{
float A,B,C,D,E,f,g,h; // variable declaration
System.out.println("Enter the value of A: \n"); //taking inpput
from user
Scanner in = new Scanner(System.in);
A = in.nextFloat(); // storing to A
System.out.println("Enter the value of B: \n"); //taking inpput
from user
B = in.nextFloat(); //storing to B
System.out.println("Enter the value of C: \n"); //taking inpput
from user
C = in.nextFloat(); //storing to c
System.out.println("Enter the value of D: \n"); //taking inpput
from user
D = in.nextFloat();
System.out.println("Enter the value of E: \n"); //taking inpput
from user
E = in.nextFloat();
f=(A+B)/C;
g=(D-A)+E;
h=f*g; // calculating expression
System.out.println("value of the arithmatic expression
(A+B)/C)*((D-A)+E) is:" + h);
}
}
Output
NOTE : if you need code in any other language u can comment on it ,it will be provided.