Tuesday 11 September 2012

Solution of Aspirations 2020-2012


                             AREA UNDER THE CURVE                                                    or                                   DEFINITE INTEGRAL                                               


#include <stdio.h>
#include <math.h>

struct Term
{
float exponent;
float coefficient;
};
double getAreaUnderCurve (struct Term* equation, int noOfTerms, int limit1,int limit2) 
{

int i;
double ans1=0,ans2=0;
struct Term *p;
p=(struct Term *)malloc(sizeof(struct Term));
p=equation;
for(i=0;i<noOfTerms;i++)
{
p->exponent=p->exponent+1;
p->coefficient=(p->coefficient)/(p->exponent);
p++;
}
p=equation;
for(i=0;i<noOfTerms;i++)
{
ans1+=(p->coefficient)*pow(limit2,p->exponent);
ans2+=(p->coefficient)*pow(limit1,p->exponent);
p++;
}
return (ans1-ans2);

}

int main() 
{
int ll,ul,n,i;
struct Term e[10];
double ans;
clrscr();
printf("Enter no of terms: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter coefficientf %d: ",i+1);
scanf("%f",&e[i].coefficient);
printf("\nEnter exponent %d: ",i+1);
scanf("%f",&e[i].exponent);
}
printf("\nEnter lower limit: ");
scanf("%d",&ll);
printf("\nEnter upper limit: ");
scanf("%d",&ul);
ans=getAreaUnderCurve(e,n,ll,ul);
printf("\n%0.4lf",ans);
return 0;
}


No comments: