Q:

PHP find output programs (conditional statements) | set 2

belongs to collection: PHP Find Output Programs

0

Find the output of PHP programs | Conditional Statements | Set 2: Enhance the knowledge of PHP conditional statements by solving and finding the output of some PHP programs.

Question 1:

<?php
    $A = 10;
    $B = 20;
    
    $R = printf("Hello : %d %d", $A, printf("%d ", $B));
    
    if ($R > 13)
    {
        echo "www.includehelp.com";
    }
    else
    {
        echo "www.google.com";
    }
?>

Question 2:

<?php
    $A = 10;
    $B = 20;
    $C = 30;
    
    if ($A > $B && $A > $C)
    {
        echo "Hello World";
    }
    else if ($B > $A && $B > $C)
    {
        echo "Hello India";
    }
    else
    {
        echo "Hello Delhi";
    }
?>

Question 3:

<?php
    $A = 10;
    $B = 20;
    $C = 30;
    
    if ($A > $B and $A > $C)
    {
        echo "Hello World";
    }
    else if ($B > $A and $B > $C)
    {
        echo "Hello India";
    }
    else
    {
        echo "Hello Delhi";
    }
?>

Question 4:

<?php
    $A = 10;
    $B = 20;
    $C = 30;
    
    if ($A > $B)
    {
        if ($A > $C) echo "Hello World";
        else echo "Hello india";
    }
    else if ($B > $A)
    {
        if ($B > $C) echo "Hiii World";
        else echo "Hiii india";
    }
    else
    {
        echo "Namaste Universe";
    }
?>

Question 5:

<?php
    $num = printf("%02d", printf("%03d", 20));
    
    if ($num % 2 == 0) echo "EVEN";
    else echo "ODD";
?>

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer1:

Output:

20 Hello : 10 3www.google.com

Explanation:

In the above program, we defined two variables $A and $B initialized with 10 and 20 respectively. Here, we used the printf() function, which is used for print formatted output. The printf() returns the total number of characters printed on the webpage.

$R = printf("Hello : %d %d",$A, printf("%d ",$B));

In the above statement, inner printf() will print "20" on the webpage and return 3, then outer printf() will print "Hello : 10 3" and return 12, which is assigned to variable $R. Then the if condition gets false, and "www.google.com" will be printed on the webpage.

Answer 2:

Output:

Hello Delhi

Explanation:

In the above program, we created three variables $A, $B, and $C initialized with 10, 20, and 30 respectively.

First of all, condition if($A>$B && $A>$C) will check, here, 10 is less than 20 and 30, then condition get false. After that else if($B>$A && $B>$C) will check, here condition also get false. Then finally else part will execute and print "Hello Delhi" on the webpage.

Answer 3:

Output:

Hello Delhi

Explanation:

In the above program, we created three variables $A, $B, and $C initialized with 10, 20, and 30 respectively.

Note: In the PHP && or and both are used to check conditions.

First of all, condition if($A>$B and $A>$C) will check, here 10 is less than 20 and 30, then condition get false. After that else if($B>$A and $B>$C) will check, here condition also gets false. Then finally else part will execute and print "Hello Delhi" on the webpage.

Answer 4:

Output:

Hiii india

Explanation:

In the above program, we created three variables $A, $B, and $C initialized with 10, 20, and 30 respectively.

Here, condition if($A>$B) will false, and else if($B>$A) condition will true, but inner condition if($B>$C) will false then "Hiii india" will be printed on the webpage.

Answer 5:

Output:

02003EVEN

Explanation:

In the above program, we used nested printf() function, the inner printf() function will print "020" and return 3, then outer printf() will print "03" and return 2, which is assigned to $num.

Now if ($num%2==0) will true, then the message "EVEN" will print on the webpage.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Find Output Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
PHP find output programs (conditional statements) ... >>
<< PHP find output programs (conditional statements) ...