Sunday, 19 August 2012

secant method


#include<stdio.h>
#include<conio.h>
#include<math.h>
float fun(float a)
{
float b;
b=a*a-4*a-10;    /*just change the equation according to your wish */
return(b);
}
float main()
{
float x1,x2,x3,f1,f2,f3,e;
printf("enter the values of x1 and x2");
scanf("%f",&x1);
scanf("%f",&x2);
printf("x1\t      x2\t         x3\t          f1\t            f2\t");
do
{
f1=fun(x1);
f2=fun(x2);
x3=((x1*f2)-(x2*f1))/(f2-f1);
e=fabs((x3-x2)/(x3));
x1=x2;
x2=x3;

printf("\n%f\t    %f\t     %f\t     %f\t    %f\t",x1,x2,x3,f1,f2);

}
while(e>0.001);

getch();
}

6 comments:

  1. #include
    #include

    void main()
    {
    FILE *o ,*s;
    int g,h,j,i,su=0;
    printf("enter lower number range\n");
    scanf("%d",&g);
    printf("enter higher number range\n");
    scanf("%d",&h);
    for(i=g;g<=h;g++)
    {
    su=g+su;
    }
    s=fopen("c.txt","w");
    fprintf(s,"%d",su);
    fclose(s);

    printf("%d",su);
    getch();
    }

    ReplyDelete
  2. #include
    #include

    int sum()
    {
    int g,h,j,i,su=0;
    printf("enter lower number range\n");
    scanf("%d",&g);
    printf("enter higher number range\n");
    scanf("%d",&h);
    for(i=g;g<=h;g++)
    {
    su=g+su;
    }
    return(su);
    };
    void main()
    {
    FILE *o ,*s;
    int g,h,j,i,su=0;
    su=sum();
    s=fopen("c.txt","w");
    fprintf(s,"%d",su);
    fclose(s);

    printf("%d",su);
    getch();
    }

    ReplyDelete
  3. it's not c++ you dickhead..

    ReplyDelete
    Replies
    1. your fucking dhoti indian... this is fucking c program...asshole

      Delete
  4. Its not f*cking working you a**holes!!!!

    ReplyDelete
    Replies
    1. why the hell dont u try then :P :3

      Delete