Code.GeekInterview.com
 
Code Samples C
 

Dichotomous Search Method


Code ResourceAuthor: katakdound  

Difficulty Level: Intermediate

Published: 7th Apr 2010   Read: 3976 times  

Filed in: C
Add Comment


 

 

Sponsored Links


 

 

Dichotomous Search Method

 


Sample Code
  1. /*program for dichotanous search
  2.  * Nitin
  3.   */
  4.  
  5. #include <stdio.h>
  6. #include <math.h>
  7. double myfunc(double x);
  8. int main()
  9. {
  10.         double (*f)(double);
  11.         double Xm, Xl=0, Xu=1;
  12.        
  13.         Xm = (Xl+Xu)/2;
  14.  
  15.         f= &myfunc;
  16.         do{
  17.                 if(f(Xl)>f(Xu)){Xu = Xm;}
  18.                 else{
  19.                         Xl = Xm;}
  20.                 printf("%fn",f(Xm));
  21.                 }while(Xm>1e6);
  22. return 0;
  23. }
  24.  
  25. double myfunc(double x)
  26. {
  27.         return (x*x);
  28. }
  29.  
Copyright GeekInterview.com


Next Article: Character Formation Using Lines


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    



Popular Coders

# Coder NameHits
1. kaivalya198933891
2. mano.mithun21566
3. deepu0817849
4. meefriend4ever8112
5. chandrikakr8081
6. sadasivathavamani7316
7. shashivaishnav7138
8. venkatakrishnansvpr7039
9. Jimmy Zorald6684
10. sripri5701

Active Coders

Refined Tags