ADVERTISEMENT
ADVERTISEMENT

PHP find output programs (basics) | set 3

Find the output of PHP programs | Basics | Set 3: Enhance the knowledge of PHP basic concepts by solving and finding the output of some PHP basic programs.
Submitted by Nidhi, on January 16, 2021

Question 1:

<?php
    $P = 5000;
    $R = 5;
    $T = 2;
?>

<?php
    $SI = ($P * $R * $T) / 100;
    print ("Simple Interest: " . $SI);
?>

Output:

Simple Interest: 500

Explanation:

In the above program, we calculated the simple interest. Here, we defined three variable $P, $R, and $T initialized with 5000, 5, and 2 respectively.

Here, we used two PHP blocks (<?php ?>). We can write any number of blocks in the PHP script.

Now coming to the expression:

$SI = ($P * $R * $T)/100;
$SI = (5000*5*2)/100;
$SI = (50000)/100;
$SI = 500;

Then we used print() function to print the value of $SI with a specified string.

Question 2:

<?php
    $P = 5000;
    $R = 5;
    $T = 2;
    
    $SI = ($P * $R * $T) / 100;
    
    print ("Simple Interest: " . '<b>' . $SI . '</b>');
?>

Output:

Simple Interest: 500

Explanation:

In the above program, we calculated the simple interest. Here, we defined three variable $P, $R, and $T initialized with 5000, 5, and 2 respectively.

Now coming to the expression:

$SI = ($P * $R * $T)/100;
$SI = (5000*5*2)/100;
$SI = (50000)/100;
$SI = 500;

Here we used '<b> … </b>' tag, which is used to print specified data in bold style. Then 500 will be printed in bold style, and "Simple Interest:" will be printed in a simple style.

Question 3:

<?php
    $P = 5000;
    $R = 5;
    $T = 2;
    
    $SI = ($P * $R * $T) / 100;
    print ("Simple<br>Interest: " . $SI);
?>

Output:

Simple
Interest: 500

Explanation:

In the above program, we calculated the simple interest. Here, we defined three variable $P, $R, and $T initialized with 5000, 5, and 2 respectively.

Now coming to the expression:

$SI = ($P * $R * $T)/100;
$SI = (5000*5*2)/100;
$SI = (50000)/100;
$SI = 500;

Here '<br>' tag is used to break the line, that's why "Simple" will  print in first line and then "Interest: 500" will be printed in second line.

Question 4:

<?php
    $A = 8;
    $B = 5;
    $C = 2;
    
    $D = $B * $B - 4 * A * C;
    
    echo $D;
?>

Output:

25

Explanation:

In the above program, we defined variable $A, $B, and $C and initialized with 8, 5, and 2 respectively.

Now coming to the expression.

$D = $B*$B - 4*A*C;

In the above expression, we used A and C instead of $A and $C. Then the value of "4*A*C" becomes 0.

Now evaluate expression:

$D = $B*$B - 4*A*C;  
$D = 5*5-0;
$D = 25;

So, 25 will be printed on the webpage.

Question 5:

<?php
    $A = 8;
    $B = 5;
    $C = 2;
    
    $D = $B * $B - 4 * $A * $C;
    
    echo $D;
?>

Output:

-39

Explanation:

In the above program, we defined variable $A, $B, and $C and initialized with 8, 5, and 2 respectively.

Now coming to the expression and evaluate:

$D = $B*$B - 4*A*C;  
$D = $B*$B - 4*A*C;  
$D = 5*5 - 4*8*2;
$D = 25 - 64;
$D = -39;

So, -39 will be printed on the webpage.



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.