Advertisement
Adiquus

zad3 php

Apr 17th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5.     <form method="post">
  6.         Liczba początkowa ciągu= <input name="x" /></br>
  7.         Różnica= <input name="r" /></br>
  8.         Ilość wyrazu ciągu= <input name="n" /></br>
  9.         <input type="submit" value="Rozwiąż" />
  10.     </form>
  11. <?php
  12.     $x = @$_POST['x'];
  13.     $r = @$_POST['r'];
  14.     $n = @$_POST['n'];
  15.    
  16.     if($x==null || $r==null || $n==null || $r==0 || $n==0 ) {echo "Wprowadź poprawne dane";}
  17.         else{
  18.             $x = @$_POST['x'];
  19.             $r = @$_POST['r'];
  20.             $n = @$_POST['n'];
  21.             $suma=0;
  22.             echo "x = $x <br>r = $r <br>n = $n<br>";
  23.            
  24.             for($i = 1; $i <= $n; $i++) {
  25.             echo "$x \n ";
  26.             $suma=$suma+$x;
  27.             $x=$x+$r;
  28.  
  29.             }
  30.             echo "<br>Suma tego ciągu wynosi $suma";
  31.         }
  32. ?>
  33.  
  34. </body>
  35. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement