Hi all! Here's the link the the prompt for the question i'm working on:
Imgur: The most awesome images on the Internet
and here is the code I have so far
// Chapter 5, #17
// This program will approximate the area
// under the curve/
Code:
#include <stdio.h>
#include <math.h>
double Trap (double A, double B, int N);
double G(double x);
double H (double a, double b, double n);
int main(void)
{
double A, B, N;
double Integral;
printf("Please Enter the Values for A:"); scanf("%lf", &A);
printf("\n");
printf("Please Enter the Values for B:"); scanf("%lf", &B);
printf("\n");
printf("Please Enter the Values for N:"); scanf("%lf", &N);
printf("\n");
Integral = (H(A, B, N)/2.0) * Trap(G(A), G(B), N);
printf("The approximate value of the area under this curve is: " "%5.2f", Integral);
printf("\n");
printf("\n");
return 0;
}
double Trap (double A, double B, int N)
{
double i;
double sum = 0.0;
i = 1;
while (i <= (N - 1.0))
{
sum = pow(i, 2) * sin(i) ;
i ++ ;
}
return (A + B + (2 * sum));
}
double G(double x)
{
return (pow(x, 2) * sin(x));
}
double H (double A, double B, double N)
{
return (B-A)/N ;
}
So i'm having some trouble setting it up as well as with the prompt.
The prompt asks me to create a function Trap with a, b, n and F as inputs
However if I create a function F and call it for Trap then input a as F(a) and b as F(b) then why do I need F as an input for F?
Furthermore if I write F as a a parameter in F i assume I would write:
(A, B, N, (pow(a, 2)* sin(a)) + pow(b, 2)* sin(b)) so then why do I need inputs A and B in This case?
Also I'm sure there's something wrong with the way I actually wrote the sum of F(x), but can't figure it out yet. Will continue working on it for now,
Can anyone offer any advice? I would greatly appreciate it!!