C C++ code- numerical differentiation of given equation

Working C C++  Source code program  for two point - three point numerical differentiation of given equation
/*****************  NUMERICAL DIFFERENTION *********************/
#include<iostream.h>
#include<conio.h>
#include<math.h>
float funct(float a);
int main()
{
    char choice='y';
    float f1,f2,x,h;
    clrscr();
    cout<<"X ? ";cin>>x;
    do{
        cout<<"Enter value of h ? ";cin>>h;
        cout<<endl<<"The derivative is: "<<endl;
        f1=(funct(x+h)-funct(x))/h;
        f2=(funct(x+h)-funct(x-h))/(2*h);
        cout<<"2 point derivative : "<<f1;
        cout<<endl<<"3 points derivative: "<<f2;
        cout<<endl<<"wanna continue (y/n) ? ";cin>>choice;
    }while(choice=='y');
    getch();
    return 0;
}
float funct(float x)
{
    return exp(x)*sin(x);
}

1 comment :

Your Comment and Question will help to make this blog better...