Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

plication8 ft Visual Studio Analyze Window Hell w Project Build Debug Team Tools

ID: 3796956 • Letter: P

Question

plication8 ft Visual Studio Analyze Window Hell w Project Build Debug Team Tools Local Windows D Debug x86 ).cpp x console application 8.cpp (Global Scope eous Files. computations disc b*b 4 a c; the discriminant r1 (-b sqrt (disc)) (2 a); root #1. r2 (-b sqrt (disc) (2 a); root #2 E if disc 0) real root case 1 (-b sqrt (disc)) (2 a); root #1 r2 (-b sqrt (disc)) (2 a); cout the roots of the equation are In"; cout r1 r1 endl. cout 2 r2 endl. E else if (disc 0) r1 b (2 a); cout The double root is r1 endl to do: add a nested if-else section here to handle the 1) one double root 2) two real roots ut from: Build

Explanation / Answer

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   float a,b,c,disc,r1,r2;
   a= 2;
   b = 4;
   c = 2;
  
   disc = b*b - 4*a*c;
   r1 = (-b + sqrt(disc))/(2*a);
   r2 = (-b - sqrt(disc))/(2*a);
  
  
   if(disc >0)
   {
   r1 = (-b + sqrt(disc))/(2*a);
   r2 = (-b - sqrt(disc))/(2*a);
   cout<<" The roots of the equation are :";
   cout<<" r1 " <<r1<<endl;
   cout<<" r2 " <<r2<<endl;
   }
   else if(disc == 0)
   {
       r1 = -b /(2*a);
       cout<<" The double root is "<<r1;
  
   }
  
   return 0;
}

output: