# equação 3 grau

· updated May 15, 2022
Fortran
```program equacao_3_grau

implicit none
integer(4)::a,b,c,d,p,q,O,P !coeficientes da equação do terceiro grau
real(8)::delta,delta1,delta2 !discriminante
real(8)::x1,x2,x3,y1,y2,y3 !raizes da equação

!leitura dos coeficientes

!impressão dos discriminates (valores)
!eq(1)  ax³+bx²+cx+d=0
write(*,*)"coeficientes da equação do terceiro grau"
write(*,*) "a=",a
write(*,*) "b=",b
write(*,*) "c=",c
write(*,*) "d=",d

!converter eq(1)
!x³+Ax²+Bx+C=0

A=b/a
B=c/a
C=d/a
write(*,*) "onde"
write(*,*) "A= b/a =",A
write(*,*) "B= c/a=",B
write(*,*) "C= d/a=",C

!translação para variavel y
!y³+py+q=0

p=B-A**2/3
q=C-A*B/3+(2/27)*A**3

write(*,*) "Constantes p e q"
write(*,*) "p=",p
write(*,*) "q=",q

!discriminante delta

delta1=q**2/4+p**3/27

write(*,*) "discriminante"
write(*,*) "delta1=",delta1

!calculo das raizes

if (delta1>=0)then
!calculo primeira y1
y1=(-q/2+(delta)**1/2)**1/3+(-q/2-(delta)**1/2)**1/3
!calculo delta2 para as  y2 e y3
delta2=-(3*y1**2+4*p)
y2=-(y1+delta2**1/2)/2
y3=-(y1-delta2**1/2)/2

else

write(*,*)"y1=",y1
write(*,*)"Para isso delta2=",delta2
write(*,*)"y2=",y2
write(*,*)"y2=",y2
endif

if (delta1<0)then
P=((q**2)/4+(delta1**2)**1/2)
O=arcos(-q/2P)
Y1=2*P**1/3*cos(O/3)
Y2=2*P**1/3*cos(O+2*3.14/3)
Y3=2*P**1/3*cos(O+4*3.14/3)

write(*,*)"P",=P
write(*,*)"O",=O
write(*,*)"Y1",=Y1
write(*,*)"Y2",=Y2
write(*,*)"Y3",=Y3
end program```
Output
`(Run the program to view its output)`