fork(3) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static double f(double x){return (-3*x*x+2*x+9);}
  8. public static double I(double a,double b,int n,double y){return ((b-a)/(2*n)*y);}
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. Scanner in = new Scanner(System.in);
  12. int n; double a,b,dy,In,y=0;
  13. a = in.nextDouble();
  14. b = in.nextDouble();
  15. n = in.nextInt();
  16. if (n>1){
  17. dy=(b-a)/n;
  18. y+=f(a)+f(b);
  19. for (int i=1; i<n; i++) {y+=2*(f(a+dy*i));}
  20. In=I(a,b,n,y);
  21. System.out.printf("%f", In);
  22. }
  23. else {System.out.printf("Wrong Data");}
  24. }
  25. }
Success #stdin #stdout 0.17s 321344KB
stdin
-1 2 25
stdout
20.978400