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;
}

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.