In: Computer Science
In C++ Please, using only the libraries given in this homework prompt,
Write a program that (1) prompts for two integers, (2) prints out their sum, (3) prints out the first divided by the second, and (4) prints out the natural log of the first number raised to the power of the second number.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
<your answer goes here>
return 0;
}
Please upvote if you are able to understand this and if there is any query do mention it in the comment section.
(1) CODE:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n1, n2;//creating two integer variables
cout << "Enter any two integers" << endl;//prompting
user for input
cin >> n1 >> n2;
return 0;
}
OUTPUT:
(2) CODE:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n1, n2;//creating two integer variables
int sum = 0;//creating the variable for sum
cout << "Enter any two integers" << endl;//prompting
user for input
cin >> n1 >> n2;
sum = n1 + n2;//adding the both the numbers
cout << "The sum of two numbers is: " << sum;
return 0;
}
OUTPUT:
(3) CODE:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n1, n2;//creating two integer variables
int sum = 0;//creating the variable for sum
double divide = 0;//creating the variable for dividie
cout << "Enter any two integers" << endl;//prompting
user for input
cin >> n1 >> n2;
sum = n1 + n2;//adding the both the numbers
divide = n1 / n2;//dividing the first number by second number
cout << "The sum of two numbers is: " << sum <<
endl;
cout << "The division of first number by second number is: "
<< divide;
return 0;
}
OUTPUT:
(4). CODE:
#include <iostream>
#include <iomanip>
#include <cmath>//importing the cmath library
using namespace std;
int main()
{
int n1, n2;//creating two integer variables
int sum = 0;//creating the variable for sum
double divide = 0;//creating the variable for dividie
int power = 0;////creating the variable for calculating power
double naturalLog = 0;
cout << "Enter any two integers" << endl;//prompting
user for input
cin >> n1 >> n2;
sum = n1 + n2;//adding the both the numbers
divide = n1 / n2;//dividing the first number by second number
power = pow(n2, n1);//using the pwer function of cmath
library
//in this first number will be raise to the power of second
number
naturalLog = log(power);//using the function of cmath library
//passing power variable as parameter to the log function to
calulate log
cout << "The sum of two numbers is: " << sum <<
endl;
cout << "The division of first number by second number is: "
<< divide << endl;
cout << "The first number raised to the power of second
number is: " << power << endl;
cout << "The natural log of first number raised to the second
number is: " << naturalLog << endl;
return 0;
}
OUTPUT:
If this was supposed to be done in any other way then please mention it in the comment section otherwise please upvote.