PHP program to demonstrate the use of printf() function

Here, we are going to demonstrate the use of printf() function in PHP?
Submitted by Nidhi, on November 18, 2020

Here, we will use the printf() function just like C programming language for formatted output.

Program/Source Code:

The source code to demonstrate the use of the printf() function is given below. The given program is compiled and executed successfully.

<?php
    //PHP program to demonstrate the 
    //use of printf() function.
    
    $A = 10;
    $B = 20;
    
    $C = $A + $B;
    printf("Sum is: %d",$C);
?>

Output:

Sum is: 30

Explanation:

In the above program, we created two local variables $A, $B that are initialized with 10 and 20 respectively. Then we assigned the sum of $A and $B to the variable $C, and then printed the sum of $A and $B using printf() function on the webpage.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





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.