M4_HAX0R

Résolution de polynômes du second degré (ax² + bx + c)

Jan 29th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.77 KB | None | 0 0
  1. <head>
  2.     <title>Equation du second degre Solver</title>
  3.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. </head>
  5. <center>
  6. <img src='http://img.memecdn.com/math_o_166669.jpg' width='350' height='269'/>
  7. <br />
  8. <?php
  9. //M4_HAX0R
  10.  
  11. @set_time_limit(0); // منع وقوف السكربت عن العمل
  12. error_reporting(0); // منع ظهرو الأخطاء
  13.  
  14. echo'<form method="GET"><big>
  15. <font color="red">a</font>x<sup><small>2</small></sup>: <input type="text" size="1" name="a" placeholder="3"/>
  16. <font color="red">b</font>x: <input type="text" size="1" name="b" placeholder="1"/>
  17. <font color="red">c</font>: <input type="text" size="1" name="c" placeholder="6"/>
  18. <input type="submit" value="SOLVE >>"/>
  19. </big></form>';
  20.  
  21.  
  22. if(!empty($_GET['a']) && !empty($_GET['b']) && !empty($_GET['c'])){ // التأكد من ادخال المعاملات
  23.     // استخراج المعاملات من الفورم
  24.     $a = trim($_GET['a']);
  25.     $b = trim($_GET['b']);
  26.     $c = trim($_GET['c']);
  27.    
  28.     // جل المعادلة
  29.     $delta = delta($a, $b, $c); // حساب العدد ضيلطا
  30.     if($delta == 0){    // ادا كان العدد ضيلطا يساوي الصفر
  31.         echo"<br />[ <b>Delta = $delta = 0</b> ]<br />"; // ذبع قيمة ضيلطا
  32.         $x = -$b/2*$a;  // الحل سيكون على الشكل التالي
  33.         // طباعة الحل
  34.         echo"<b><i>x</i> =  <sup>-$b</sup>&frasl;<sub>2*$a</sub><font size='4' face='Arabic Transparent'>   :ادا للمعادلة حل وحيد هو</font></b><br />";
  35.         echo'<br /><font color="blue" size="6">S={</font><big><b>'.$x.'</b></big><font color="blue" size="6">}</font>';
  36.     }elseif($delta>0){  // ادا كان ضيلطا اكبر من الصفر
  37.         echo"<br />[ <b>Delta = $delta > 0</b> ]<br />"; // ذبع قيمة ضيلطا
  38.         // حلول المعادلة
  39.         $x1 = (-$b-sqrt($delta))/(2*$a);
  40.         $x2 = (-$b+sqrt($delta))/(2*$a);   
  41.         // طباعة الحل
  42.         echo"<b><i>x</i> =  <sup>-$b <i><u>+</u></i>√$delta</sup>&frasl;<sub>2*$a</sub><font size='4' face='Arabic Transparent'>  :للمعادلة حلين حقيقيين مختلفين هما</font></b><br />";
  43.         echo'<br /><font color="blue" size="6">S={</font><big><b>'.$x1.', '.$x2.'</b></big><font color="blue" size="6">}</font>';      
  44.     }else{ // ادا كانت ضيلطا اصغر من الصفر فهي الاختيار الوحيد المتبقي ههه
  45.         echo'<br /><font size="5" face="Arabic Transparent"> <big><i>R</i></big> ليس للمعادلة حل في</font></b>'; // طبع ان ليس للمعادلة حل في المجموعة اغ
  46.     }
  47.    
  48. }
  49.  
  50. function delta($a, $b, $c){ // دالة لحساب قيمة ضيلطا
  51.     return pow($b, 2)-4*$a*$c;
  52. }
  53.  
  54. /*
  55. pow function: http://www.w3schools.com/php/func_math_pow.asp
  56. sqrt function: http://www.w3schools.com/php/func_math_sqrt.asp
  57. */
  58. ?>
Add Comment
Please, Sign In to add comment