C Program to find the root of the quadratic equation
write(*,*)'Enter the values of a,b,c'
read(*,*)a,b,c
d=b*b-(4.0*a*c)
if (d.eq.0)then
write(*,*)'The root is real and equal.'
x1=-b/(2.0*a)
write(*,*)'The equal root is :',x1
else if (d.gt.0)then
write(*,*)'The roots are real and distinct.'
x1=(-b+sqrt(d))/(2.0*a)
x2=(-b-sqrt(d))/(2.0*a)
write(*,*)'The roots are :',x1,' and ',x2
else
write(*,*)'The roots are distinct but imaginary.'
x1=(-b)/(2.0*a)
x2=sqrt(-d)/(2.0*a)
write(*,*)'The first root is :',x1,'+i',x2
write(*,*)'The second root is :',x1,'-i',x2
end if
end
write(*,*)'Enter the values of a,b,c'
read(*,*)a,b,c
d=b*b-(4.0*a*c)
if (d.eq.0)then
write(*,*)'The root is real and equal.'
x1=-b/(2.0*a)
write(*,*)'The equal root is :',x1
else if (d.gt.0)then
write(*,*)'The roots are real and distinct.'
x1=(-b+sqrt(d))/(2.0*a)
x2=(-b-sqrt(d))/(2.0*a)
write(*,*)'The roots are :',x1,' and ',x2
else
write(*,*)'The roots are distinct but imaginary.'
x1=(-b)/(2.0*a)
x2=sqrt(-d)/(2.0*a)
write(*,*)'The first root is :',x1,'+i',x2
write(*,*)'The second root is :',x1,'-i',x2
end if
end
Comments
Post a Comment