السلام عليكم ورحمة الله وبركاته
اخواني
ممكن تصلحولي هذا الكود
Problem #3 (25 Pts.)
Write only one function that calculates the two roots of the quadratic equation (use references). The function returns an integer value. The returned value could be one of the following:
- The returned value equals to zero if the value of A is zero.
- The returned value equals to one if the value under the square root is negative.
- The returned value equals to two if the values of A, B, and C are appropriate for calculating the two roots.
Write a driver program (main function) to test the above function and display appropriate messages.
#include<iostream>
#include<cmath>
using namespace std;
int Roots(int&,int&,int&);
int main()
{
int A,B,C;
int D,x1,x2;
cout<<"enter value for A,B and c "<<endl;
cin>>A;
cin>>B;
cin>>C;
Roots(A,B,C);
return 0;
}
int Roots(int&,int&,int&)
{
int A,B,C;
cout<<"enter value for A,B and c "<<endl;
cin>>A;
cin>>B;
cin>>C;
int D,x1,x2,b;
D= B*B-(4*A*C);
x1= ( -b+sqrt(D))/(2*A);
x1=( -b-sqrt(D))/(2*A);
if (A=0)
return 0;
else if (D<0)
return -b/C;
else
return x1;
}
طالبة لIt
