c++ code is given below #include<iostream.h> #include<conio.h> int bsearch(int[],int,int); void main() {clrscr(); int ar[50],item,n,index; cout<<"\n enter the size of array :"; cin>>n; cout<<"\n enter the elements of the array:"; for(int i=0;i<n;i++) cin>>ar[i]; cout<<"\n enter the elements to be searched:"; cin>>item; index= bsearch(ar,n,item); if(index==-1) cout<<"\n sorry the no. is not found"; else cout<<"\n element found at index:"<<index<<" position"<<index+1; getch(); } int bsearch(int ar[],int n,int item) {int beg,last,mid; beg=0; last=n-1; while(beg<=last) { mid=(beg+last)/2; if(item==ar[mid])...
Posts
newton raphson method is a method to solve equations in numerical techniques. #include<iostream.h> #include<conio.h> #include<math.h> const double epsilon=0.00001; float f(float x) { float fx1; fx1=pow(x,4)+pow(x,2)-80; return fx1; } float f_dash(float x) { float fx2; fx2=4*pow(x,3)+2*x; return fx2; } void main() { cout.setf(ios::fixed); cout.setf(ios::showpoint); clrscr(); float x0,c; cout<<"Enter initial approximation\n"; cout<<"x0="; cin>>x0; cout<<"\nx0\t\tf(x0)\t\tf'(x0)\t\tc\n"; cout<<endl; c=x0-(f(x0)/f_dash(x0)); while(fabs(x0-c)>=epsilon) { cout<<x0<<"\t"<<f(x0)<<"\t"<<f_dash(x0)<<"\t"<<c<<endl; ...