Skip to content

Instantly share code, notes, and snippets.

@randaalex
Created June 7, 2013 19:58
Show Gist options
  • Save randaalex/5731988 to your computer and use it in GitHub Desktop.
Save randaalex/5731988 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <iostream>
#include <math.h>
using std::cout;
using std::cin;
using std::endl;
int main(void)
{
double m, r, result;
cout << "\n\t Input m, r ";
cin >> m >> r;
if((r <= m) && (m <= 2*r)){
result = sqrt(fabs(3*m - 5*r)) * exp(m/r);
} else {
if( m > 2*r ){
result = sqrt(fabs(3*m + 5*r)) * exp(r/m);
} else {
cout << "\n\t ERROR!" << endl;
return 1;
}
}
cout << "\n\t Result: rez = " << result << endl;
// uncomment under windows
// cout << "\n Press any key ... " << endl;
// getch();
return 0;
}
@randaalex
Copy link
Author

$ c++ task2.cpp; ./a.out 

     Input m, r 6 5

     Result: rez = 8.7842

$ c++ task2.cpp; ./a.out 

     Input m, r 5 1

     Result: rez = 5.46228

@randaalex
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment