Here I have written a simple piece of code in C Programming Language which merges the both aspects of calculus and programming.
This piece of code uses a well known method called "The Trapezium Rule" to calculate the area between the curve.
Here I have written the code for two forms algebric form and trigonometric form.
The equation for algebric form is y = x^2 + X
The equation for trigonometric form is y = (1+(sinx*sinx))^1/2
The program for algebric form is :
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int a,b,y, area=0, x=0;
int h=2;
printf("Enter the value of a \n");
scanf("%d",&a);
printf("Enter the value of b \n");
scanf("%d",&b);
while (x<b)
{
y= x*(x+1);
area = area+ (h*y);
x = x+h;
}
printf("Total area is : %d \n ",area);
system("pause");
return(1);
}
The code for trigonometric form is:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int a,b,y, area=0, x=0;
int h=2;
printf("Enter the value of a \n");
scanf("%d",&a);
printf("Enter the value of b \n");
scanf("%d",&b);
while (x<=b)
{
y= sqrt(1+(sin(x)*sin(x)));
area += (h*y);
x+= h;
}
printf("Total area is : %d \n ",area);
system("pause");
return(1);
}
Peace Out Hombres!
0 comments:
Post a Comment