onilink_ Modérateur
Messages : 9180 Localisation : Montpellier Projet Actuel : Planet Centauri
OniDev
| Sujet: Resoudre une equation du second degres Jeu 1 Oct 2009 - 18:09 | |
| Résout les equation du second degres de la forme ax² + bx + c = 0 Donne aussi les solutions complexes. - Code:
-
if !variable_local_exists('create') { a = get_integer('a = ',0) b = get_integer('b = ',0) c = get_integer('c = ',0)
D = b*b - 4*a*c
if (D > 0) { x1 = (-b+sqrt(D))/(2*a) x2 = (-b-sqrt(D))/(2*a) } else if (D == 0) { x_ = -b/(2*a) } else if (D < 0) { x1r = -b/(2*a) x1i = -sqrt(-D)/(2*a) x2r = -b/(2*a) x2i = sqrt(-D)*(2*a) } create = 0 }
if !keyboard_check(vk_space) { draw_text(8 ,8 + 16*0 ,"a = "+string(a) ) draw_text(8 ,8 + 16*1 ,"b = "+string(b) ) draw_text(8 ,8 + 16*2 ,"c = "+string(c) )
draw_text(8 ,8 + 16*4 ,"D = "+string(D) )
if D>0 { draw_text(8 ,8 + 16*6 ,"x1 = "+string(x1) ) draw_text(8 ,8 + 16*7 ,"x2 = "+string(x2) ) } else if D==0 draw_text(8 ,8 + 16*6 ,"x = "+string(x_) ) else if D<0 { draw_text(8 ,8 + 16*6 ,"x1 = "+string(x1r)+" + "+string(x1i)+"i" ) draw_text(8 ,8 + 16*7 ,"x2 = "+string(x2r)+" + "+string(x2i)+"i" ) } }
if !keyboard_check(vk_space) exit
draw_line(0,240,640,240) draw_line(320,0,320,480)
for(i=-16 ; i<=16 ; i+=0.05) { j = i+0.05 draw_line(i*20 +320, -(a*i*i + b*i + c) + 240 , j*20 +320 , -(a*j*j + b*j + c) + 240 ) draw_line(i*20*10*2,240-4,i*20*10*2,240+4) draw_line(i*20*10,240-2,i*20*10,240+2) }
|
|