Question # 1
Write a program that can input two number from user and then it will print their addition, subtration, multiplication and division.
Program
// program for Add sub multiplication
// Division and to find average of two number
// Header files
#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
int main()
{
// Veriables declaration
int num1, num2, add, sub, mul;
double div, average, num3, num4, sum;
// To show point
cout << fixed << showpoint << setprecision(2);
// prompt the user to enter numbers
cout << "Enter your First number ";
cin >> num1;
cout << "Enter your Second number ";
cin >> num2;
// operations
add = num1 + num2;
sub = num1 - num2;
mul = num1 * num2;
// To show result on the secreen
cout << "Addition of Number is = " << add << endl;
cout << "subtraction of Number is = " << sub << endl;
cout << "Multiplicaion of Number is = " << mul << endl;
// To convert integer type to float
num3 = static_cast<float>(num1);
num4 = static_cast<float>(num2);
sum = static_cast<float>(add);
// again operations
div = num3 / num4;
average = add / 2;
// To show results
cout << "Division of Number is = " << div << endl;
cout << "Aerage of Number is = " << average << endl;
return 0;
}
0 Comments