Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. double f(double x)
  6. {
  7. return -(x*x)/50;
  8. }
  9.  
  10. double g(double x)
  11. {
  12. return 1+(x*x)/100-x/200;
  13. }
  14.  
  15. double pole(double c,int ile)
  16. {
  17. double x;
  18. double p=0;
  19. double dlugosc=c/ile;
  20.  
  21. for(int i=0; i<ile;i++)
  22. {
  23. x=(dlugosc*i)+(dlugosc/2);
  24. p=p+dlugosc*fabs(g(x)-(f(x)));
  25. }
  26. return p;
  27. }
  28.  
  29. double prostokat(int c){
  30. int x=0;
  31. for(int i=0;i<c;i++){
  32. if(fabs(f(i))>=26){
  33. x = i;
  34. break;
  35. }
  36. }
  37. return x;
  38. }
  39.  
  40. int main()
  41. {
  42. int ile;
  43. double c;
  44.  
  45. cout<<"Podaj C (ograniczenie przedziału z prawej strony): ";
  46. cin>>c;
  47. cout<<"Na ile przedzialow podzielic wyjsciowy przedzial: ";
  48. cin>>ile;
  49. // cout<<"wartosc pola to: "<<pole(c,ile)<<endl;
  50. double liczba = prostokat(c);
  51. double a = fabs(ceil(f(liczba)))-fabs(f(liczba));
  52. if(c < liczba+a+100){
  53. cout<<"c musi byc wieksze od "<<ceil(liczba+a+100);
  54. return 0;
  55. }
  56. cout<<endl<<"1. "<<"("<<liczba<<" , "<<"0"<<")";
  57. cout<<endl<<"2. "<<"("<<liczba<<" , "<<ceil(f(liczba))<<")";
  58. cout<<endl<<"3. "<<"("<<liczba+100<<" , "<<"0"<<")";
  59. cout<<endl<<"4. "<<"("<<liczba+100<<" , "<<ceil(f(liczba))<<")";
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement