jsam
2/18/2014 - 4:37 PM

old integral

old integral

#include<iostream.h>    //for cout & cin
#include<conio.h>       //for getch() & clrscr()
#include<math.h>        //for any mathematical function
#define n 100000;

void main()
{
   clrscr();
   double a,b,temp,s=0.0,x;
   double y;
   cout<<"Enter the lower limit:";
   cin>>a;
   cout<<"Enter the upper limit:";
   cin>>b;
   if(a>b)    //swapping a & b if a>b so that area comes positive
   {
     temp=a;
     a=b;
     b=temp;
   }
   for(double i=a;i<b;i+=(b-a)/n)
   {
      x=i;
      y=x*x;    //you can  set any f(x)
      s+=y*(b-a)/n;
   }
   cout<<"area equals: "<<s;
   getch();
}