Last active
August 29, 2015 13:56
-
-
Save jsam/9074485 to your computer and use it in GitHub Desktop.
old integral
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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