Instructions:Write a program that reads two numbers and store them into variables double x,y; Then the code finds double M the maximum of the two numbers and prints its value.
So far i got
#include <iostream>
using namespace std;
int main() {
double x , y, M;
cout << " Enter the value of x."<<endl;
cin >> x;
cout << " Enter the value of y."<<endl;
cin >> y;
cout << "The maximum of the two numbers is" << M <<endl;
Am i suppose to put #include <math.h> to find maximum???
how do i do "Then the code finds double M the maximum of the two numbers and prints its value."
the above code is correct for the task that you originally mentioned. You did not mention " find the minimum of three variables " so I can only assume what you provide. The second task will required similar code from above except the opposite and with three variables to check. Many ways to solve that problem. To me, it sounds like maybe you just need to take many integers as input and then just sort them from smallest to largest. This would require an array. But again, I am not sure what the requirements are of the assignment. Are you in a college class?
Instructions:Write a program that reads three numbers and stores them into variables double x,y, z; Then the code finds double m the minimum of the three numbers and prints its value.
I only learned the basics up to if or else functions and while loops.
Not sure what an array is. I think we didnt learn that yet.
Are you a college student? I am asking because I am a CS student at Uni. I wish my assignments were this easy. But then again, at one point they may have been and I just forgot. Happy coding
Use some logic:
in This logic u can get max and minimum no. both:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int n,x,l,s;
for (n=1;n<=3;n++)
{
cout<<"\nEnter any no ";
cin>>x;
// assuming that the first no is largest no & smallest no
if (n==1)
{ l=x;
s=x;}
if (x>l)
l=x;
if (x<s)
s=x;
}
cout<<"\nThe largest no is "<<l;
cout<<"\nThe smallest no is "<<s;
I would personally recommend because is very cool and allows you to do simple way of programming
cbtsam