Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1. Exchange value
- <!--Write an if statement that examines two integer variables and exchanges their values if the first one is greater than
- the second one.-->
- <h1 style="font-size: 1.2em">Change Variable Value</h1>
- <form action="1_ExchangeValue.php" method="post">
- <input type="text" name="a" value="a"><br>
- <input type="text" name="b" value="b">
- <input type="submit" value="Go">
- </form>
- <?php
- if(isset($_POST['a'],$_POST['b'])){
- $a = $_POST['a'];
- $b = $_POST['b'];
- echo "a= ".$a.",b= ".$b.'<br>';
- if($a>$b){
- $c = $a;
- $a = $b;
- $b = $c;
- echo 'Result: ';
- echo "a= ".$a.",b= ".$b;
- } else {
- echo 'Change value only when a>b!';
- }
- }
- ?>
- //2. Show sign
- //3. Sort numbers
- <!--Sort 3 real values in descending order using nested if statements.-->
- <?php
- $numbers = array("a" => 5, "b" => 4, "c" => 3, "d" => 2);
- asort($numbers);
- foreach ($numbers as $key => $val) {
- echo "$key = $val.<br>";
- }
- ?>
- //4. Point in a Circle
- <!--Write an expression that checks if given point (x, y) is inside a circle K({0, 0}, 2). Examples:
- x y inside
- 0 1 true
- -2 0 true
- -1 2 false
- 1.5 -1 true
- -1.5 -1.5 false
- 100 -30 false
- 0 0 true
- 0.2 -0.8 true
- 0.9 -1.93 false
- 1 1.655 true-->
- <h1 style="font-size: 1.2em">Point in a Circle</h1>
- <form action="4_PointInCircle.php" method="post">
- <input type="text" name="x" value="x"><br>
- <input type="text" name="y" value="y">
- <input type="submit" value="Go">
- </form>
- <?php
- if(isset($_POST['x'],$_POST['y'])){
- $x = $_POST;
- $y = $_POST;
- $circle = (($x*$x)+($y*$y))<=2*2;
- echo $circle ? 'True':'False';
- }
- ?>
- //5. Matrix of Numbers
- <!--Write a program that reads from the console a positive integer number n (1 ≤ n ≤ 20) and prints a matrix like in the
- examples below. Use two nested loops. Examples:
- n matrix n matrix n matrix
- 1 2
- 2
- 2 3 3
- 1 2 3
- 2 3 4
- 3 4 5
- 1 2 3 4
- 2 3 4 5
- 4
- 3 4 5 6
- 4 5 6 7-->
- <h1 style="font-size: 1.2em">Matrix Of Numbers</h1>
- <form action="5_MatrixOfNumbers.php" method="post">
- <input type="text" name="a" value="x"><br>
- <input type="submit" value="Go">
- </form>
- <?php
- if(isset($_POST['a'])){
- $n = $_POST['a'];
- for ($row = 1; $row <= $n; $row++) {
- for ($i = $row; $i < $n+$row; $i++) {
- //echo ' ','<br>';
- echo $i;
- echo ' ';
- }
- echo ' '.'<br>';
- }
- }
- ?>
- //6. Odd and Even Product
- //7. TOTO
- for ($i = 1; $i <=40; $i++) {
- for ($j = $i+1; $j <=41; $j++) {
- for ($y = $j+1; $y <=42; $y++) {
- echo $i.' '.$j.' '.$y;
- }
- }
- }
- ?>
- //8. Print Prime Numbers
- <?php
- function prime($n){
- for($i=1;$i<=$n;$i++){
- $counter = 0;
- for($j=1;$j<=$i;$j++){
- if($i % $j==0){
- $counter++;
- }
- }
- if($counter==2){
- print $i." is Prime <br>";
- }
- }
- }
- prime(100);
- //9. Extract words
- <!--Write a function that takes as argument an array, and extract all the words from that array without repeating the
- same ones.
- Array result
- Nakov,
- Svetlin,
- Nakov, Pesho,
- Mario,
- Dimityr,
- Georgi, Mario
- Nakov, Svetlin,
- Pesho, Mario,
- Dimityr,Georgi-->
- <?php
- $input = array("Nakov", "Svetlin","Nakov", "Pesho", "Mario","Dimityr","Georgi","Mario");
- print_r(array_unique($input));
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement