Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // prog5_functions.c
- // prog5_integral
- //
- // Created by James Moriarty on 10/25/16.
- // Copyright © 2016 James Moriarty. All rights reserved.
- //
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <math.h>
- #include "prog5_functions.h"
- double base, t;
- float a,b,n;
- int i;
- double sum=0;
- double v;
- // Calculate integral of f(x) over interval min to max, using n trapezoids
- double integrate(double min, double max, int n) {
- base = (b-a)/n;
- sum = (0.5*base)*(f(a)+f(b));
- for (i = 0; i < n; i++) {
- sum= sum + base * f(a+(i*base));
- }
- //function
- double f(double x){
- v = sin(x)+((x*x)/10);
- return v;
- }
- // Used to clear line if input formatting error occurs
- void badInput() {
- do {
- scanf("%c", &junk);
- } while (junk != '\n');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement