Skip to main content

Internal Exam


    HTML CODE:
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1">
    6. <title>PHP Operations</title>
    7. </head>
    8. <body>
    9. <form action="p1.php" method="post">
    10. <label>Enter First String:</label>
    11. <input type="text" name="n1"><br>
    12. <label>Enter Second String:</label>
    13. <input type="text" name="n2"><br>
    14. <input type="submit" name="enter" value="Enter">
    15. </form>

    16. </body>
    17. </html>


    PHP CODE:
    1. <?php

    2. $str1 = $_POST['n1'];
    3. $str2 = $_POST['n2'];

    4. function mod($str1 , $str2)
    5. {
    6. $mod = $str1 % $str2;
    7. echo "mod is ".$mod."<br>";
    8. }
    9. mod($str1, $str2);

    10. function power($str1, $str2)
    11. {
    12. $power = $str1 ** $str2;
    13. echo "power is ".$power."<br>";  
    14. }
    15. power($str1, $str2);

    16. function sum($str1)
    17. {
    18. $sum = 0;
    19. for ($i=1; $i<=$str1 ; ++$i) 
    20. $sum = $sum + $i;
    21. }
    22. echo "sum of First ".$str1." numbers is ".$sum."<br>";
    23. }

    24. sum($str1);

    25. ?>

    OUTPUT:

    First Number: 4
    Second Number: 2 
    mod is 0
    power is 16
    sum of First 4 numbers is 10