Skip to content

Instantly share code, notes, and snippets.

@jsam
Last active August 29, 2015 13:56
Show Gist options
  • Save jsam/9074485 to your computer and use it in GitHub Desktop.
Save jsam/9074485 to your computer and use it in GitHub Desktop.
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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment