Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. //
  2. //  prog5_functions.c
  3. //  prog5_integral
  4. //
  5. //  Created by James Moriarty on 10/25/16.
  6. //  Copyright © 2016 James Moriarty. All rights reserved.
  7. //
  8.  
  9. #define _CRT_SECURE_NO_WARNINGS
  10. #include <stdio.h>
  11. #include <math.h>
  12. #include "prog5_functions.h"
  13.  
  14.  
  15. double base, t;
  16. float a,b,n;
  17. int i;
  18.  
  19. double sum=0;
  20. double v;
  21. // Calculate integral of f(x) over interval min to max, using n trapezoids
  22. double integrate(double min, double max, int n) {
  23.     base = (b-a)/n;
  24.     sum = (0.5*base)*(f(a)+f(b));
  25.     for (i = 0; i < n; i++) {
  26.         sum= sum + base * f(a+(i*base));
  27.     }
  28.    
  29.     //function
  30.     double f(double x){
  31.  
  32.         v = sin(x)+((x*x)/10);
  33.         return v;
  34.         }
  35. // Used to clear line if input formatting error occurs
  36. void badInput() {
  37.     do {
  38.         scanf("%c", &junk);
  39.     } while (junk != '\n');
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement