Skip to main content
Home
Live to Learn!

Main navigation

  • Home
  • Learn
    • FoxPro
    • MS-DOS
    • C PRG
    • Java
    • ASP
    • Ruby on Rails
    • ASP.NET
    • E-Books
    • Exam Preparation
    • Tools
  • Blog
  • Forums
  • Contact
User account menu
  • Log in

Breadcrumb

  1. Home
  2. C Programming

Bisection Method

Book navigation

  • C Programming Introduction
  • C – Program Code – Basics Part I
  • C – Program Code – Basics Part II
  • Operators in C Programming
  • C – Program Code – Basics Part III
  • C Program Code Basics - Part IV
  • Addition , Subtraction and Multiplication of Matrices
  • Solving Quadratic Equation
  • Sum of sin series
  • Sum of cos series
  • Sum of e series
  • Ascending and Descending order
  • Sorting in Alphabetical Order
  • Factorial of a number
  • Fibonacci Series
  • String Counting
  • String Manipulation
  • Bisection Method
  • Newton Raphson Method
  • Lagrange's Interpolation
By Karthikeyan , 8 September, 2009

Sample C program that uses Bisection Method in mathematics


#include
#include
#include
float function(float x)
{
    float f;
	f= (x*x*x)-4*x-9;/*Given Function*/
    return(f);
}

void design()
{
    int m;
    printf("\n");
    for(m=1; m<80;m++)
    printf("*");
}

main()
{
    float x0 = 0.0, v = 0.0, x1=0.0, f0, f1, f2, x2, x, e;
	int i;
	clrscr();
    printf("\n\t\t Bisection Method");
    printf("\n\t\t ****************");
	printf("\n");
	printf("Given Function x^3 - 4x - 9 = 0\n");
	printf("Enter Accuracy : ");
	scanf("%f", &e);
	values:
	   x0 = v;
       x1 = x1 +1;
	   f0 = function(x0);
	   f1 = function(x1);
	   v = x1;
	if ((f0*f1)>0.0)
	goto values;
	else
	{
		design();
		printf("\n\t x0\t  x1\t   x2\t  f0\t  f1\t  f2");
        design();
        do
        {
            f0 = function(x0);
            f1 = function(x1);
            x2 = (x0 + x1)/2;
            f2 = function(x2);
			printf("\n %7.4f\t%7.4f\t%7.4f\t%7.4f\t%7.4f\t%7.4f\t", x0,x1,x2,f0,f1,f2);
            if((f0*f2)<0)
            x1 = x2;
            else
            x0=x2;
        }
		while(fabs((x0-x1)/x1)>=e);
        printf("\n");
        design();
		printf("\n\t\t Root can varges at = %7.4f\t", x2);
		design();
	  }
	  getch();
}

Comments

Featured Blog Posts

Convert Currency in Number to Words (Indian Rupees) - MS Excel
Foxpro Tutorial and Programs
Convert Currency in Number to Words in MS Word
Convert Currency in Number to Words (Indian Rupees) - Version 2
Best way to Use Rupee Symbol in Windows – Easy steps
Convert Currency in Number to Words - MS Access
Creating All in One Windows XP DVD with all Important Applications
RSS feed

© 2009-2025 Live to Learn.In

Terms of Use | Privacy Policy