In: Computer Science
Using C++ code, write a program named q5.cpp to print the minimum of the sums x + y^3 and x^3 + y, where x and y are input by a user via the keyboard.
C++ code:
#include <iostream>
#include <cmath>
using namespace std;
int main(){
//initializing x and y
int x,y;
//asking for x and y
cout<<"Enter x and y: ";
//accepting them
cin>>x>>y;
//checking if the first sum is smaller than
second
if(x+pow(y,3)<pow(x,3)+y)
//printing the first sum
cout<<"Minimum is
"<<x+pow(y,3)<<endl;
else
//printing the second sum
cout<<"Minimum is
"<<pow(x,3)+y<<endl;
return 0;
}
Screenshot:
Input and Output: