0

hi all
i have a problem and i hope someone will help me.
i have this program and i want to find the absolute maximum difference between y1 and y2 ??!!
i have found the difference between y1 and y2 but i could not find the maximum difference between them!!!
I mean the maximum difference for all the numbers .
for example, if we have
y2-y1=23
y2-y1=20
y2-y1=12
y2-y1=40
then the maximum difference = 40

#include<iostream> 
#include<iomanip> 
#include<cmath> 
using namespace std;

int main() 
{
//Declaration and Initialization
const double e=2.718282;
int random,i(1);
double y1,y2;
double r;
cout<<"Enter the number of random values to be entered: ";
cin>>random;
cout<<"\n\nx\t"<<"exact root(y1)\t"<<"estimated root(y2)\t"
<<" The differnce between roots"<<"\n";
while(i<=random)
}
r=rand()%((20000/1000)-(5000/1000))+5000/1000; 
y1=sqrt(r); 
y2=e*(.5*log(r));
cout<<setprecision(3)<<r<<"\t"<<setprecision(6)<<y1<<" \t"<<setprecision(6)
<<y2<<"\t"<<setprecision(6)<<" "<<fabs(y2-y1)<<endl;
i++; 
}
return 0;
}

Edited by WaltP: Added CODE Tags -- please use them (not that it helped)

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Moschops
0

Amm ..it is not clear yet
can you explain more please or can you give me an example??

0

Get all y2 values. Find largest.
Get all y1 values. Find smallest.

Subtract smallest y1 from largest y2. That's the number you're looking for.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.