 Error in the code

#include
#include<math.h>
using namespace std;
int main() {
int a,b,c;
cin>>a>>b>>c;
if(a == 0){
cout<<“invalid”;
return 1;
}
int delta = (bb)-(4ac);
//cout<<delta;
if(delta<0){
cout<<“imaginary”;
}
else if(delta>0){
cout<<“Real and Distinct”<<endl;
int root1= (-b+sqrt(delta))/(2
a);
int root2= (-b-sqrt(delta))/(2a);
if(root1<root2)
cout<<root1<<" “<<root2;
else
cout<<root2<<” "<<root1;
}
else if(delta==0){
int root= (-b)/(2
a);
cout<<“Real and equal”<<endl;
cout<<root<<" "<<root;
}
return 0;
}

@umnah1103_2205d5eee7973385 your code logic is correct there is a very small mistake ,
while doing division in int root1= (-b+sqrt(delta))/(2* a); value of sqrt may be float but since you are taking everything as integer this will affect the final result .
instead you should first typecast (-b+sqrt(delta)) to float and then to int

eg - int(float(-b+sqrt(delta))/(2* a));

do this everywhere where there is a division.

Hope this helps Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

after this also i am not able to pass test case although custom input running perfectly

#include #include<math.h> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; if(a == 0){ cout<<“invalid”; return 1; } int delta = (bb)-(4ac); //cout<<delta; if(delta<0){ cout<<“imaginary”; } else if(delta>0){ cout<<“Real and Distinct”<<endl; int root1= int(float(-b+sqrt(delta))/(2a)); int root2= int(float(-b-sqrt(delta))/(2a)); if(root1<root2) cout<<root1<<" “<<root2; else cout<<root2<<” "<<root1; } else if(delta==0){ int root= int(float(-b)/(2a)); cout<<“Real and equal”<<endl; cout<<root<<" "<<root; } return 0; }

hi @umnah1103_2205d5eee7973385
refer this -->