Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
QuadRootPoint
//g++ 7.4.0 //write a function to calculate the roots of a quadratic equation; the function must use two pointer parameters, one to receive the coefficients a,b and c, and the other to send the roots to the calling function //this code is created by Rezaul Hoque on July 25,2021;contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> #include <cmath> using namespace std; //getroot function does the required task; it takes a constant pointer and an array of pointers to float; note the function returns a pointer float* getroot(float const*,float* []); float * getroot(float const* a,float* c[]){ int n2=2; float * const p= new float[n2]; for(int l=0; l<n2; l++) p[l]= *c[l]; // p is also an array of pointers to float and it is assigned to point the values indicated by c[] return p; } int main(){ int n=3,n2=2; float a[n];//array a holds the coefficients and the array name itself is a constant pointer; here this logic is employed cout<<"Enter values of a,b and c:\n"; for(int l=0; l<n; l++) cin>>a[l]; //here a[0] is a,a[1] is b and a[2] is c float b[n2]; float discrim; discrim=a[1]*a[1]-(4*a[0]*a[2]); if(discrim<0) cout<<"Roots are imaginary.\n"; else { b[0]= (-a[1] + sqrt(discrim))/(2.0*a[0]); b[1]= (-a[1] - sqrt(discrim))/(2.0*a[0]); } float* c[n2]; for(int l=0; l<n; l++) c[l]=&b[l];//c[] is an array of pointers to float and it points to values of array b[] float * const p= getroot(a,c);//returned pointer is assigned to p,which is also a pointer for(int l=0; l<n2; l++){ cout<<*(p+l); cout<<"\n"; } return 0; }
run
|
edit
|
history
|
help
0
PhoneDirectory
count common elements in three sorted array without using extraspace
Speed
designated-inits
1068 - Investigation
sdfg
Get all anagrams from given words
Couting number of substring occurances in C++
scemo dd
Test 9(2021)