Write a program to input 5 numbers and find the sum and product it.
Answers
import java.util.*;
public class Sum_Product
{
public static void main(String args[])
{
//using scanner class
Scanner in = new Scanner(System.in);
//scanner class is mandatory for taking input
int m,n,o,p,q,sum,product;
//accepting the values
System.out.println("Enter the numbers");
m=in.nextInt();
n=in.nextInt();
o=in.nextInt();
p=in.nextInt();
q=in.nextInt();
sum=(m+n+o+p+q);
System.out.println("The sum is" +sum);
product=(m*n*o*p*q);
System.out.println("The product is" +product);
}
}
Answer:
In Java and c++
Step-by-step explanation:
Java(blue j)
Class sumpro
{
Void main( int a, int b, int c, int d, int e)
{
System.out.println(a+b+c+d+e);
System.out.println(a*b*c*d*e);
}
}
In c++
class sumpro
{
private: int a,b,c,d,e;
public: void sum();
void product();
};
Void sumpro::sum()
{
cin>>a>>b>>c>>d>>e;
cout<<(a+b+c+d+e);
}
Void sumpro::product()
{
cout<<(a*b*c*d*e);
}
Void main()
{
Sumpro s;
s.sum();
s.product();
}