×

Please Login or Register to continue.

3
(1.6K Views)

Programming cannot be done without mathematics logic. I want to solve (a+b)2 in the PHP programming language. I am a beginner in PHP. I won't use the mathematics formula  (a+b)2 in the PHP  language. How can convert the mathematics formula (a+b)2 in PHP? It is a famous mathematical formula.

 

(2.4K Points)
in PHP

Share

1 Answer
(9.4K Points)
(edited)
0

PHP programming is based on operators and operands. If you are already learned operators in the C language, you will understand easily. You can use mathematics formula (a+b) in the PHP language. First of all, you need to learn about PHP data types.

Think about the variables in mathematics formula (a+b)2 There is two variable in this formula a and b.

How to open the mathematics formula (a+b)2  

(a+b)2=a2+b2+2ab

How can write the line mathematics line a2+b2+2ab

a2+b2+2ab=a*a+b*b+2*a*b

if a=2 and b=4

then,

a2+b2+2ab=2*2+4*4+2*2*4

= 4+16+16

=36

You can use this mathematics logic in PHP programming

 

Asterisk sign (*) is used for multiplication in computer programming languages.

We declare the variables in PHP like this –

$a;

$b;

Use the above mathematics login –

a*a+b*b+2*a*b

Let’s create a program for mathematics formula (a+b)2 in PHP language –

<?php
$a=5;
$b=6;
echo "(a+b)<sup>2</sup>=a<sup>2</sup>+b<sup>2</sup>+2ab";
$result=($a*$a+$b*$b+2*$a*$b);
echo "=".$result;
?>

You will get the result as output –

(a+b)2=a2+b2+2ab=36

 

You can change variables (a,b) values according to your needs.


Comment

Related Questions :-

Featured Items:-


Certificate and Marksheet system with verification & Franchise in PHP

$75



Certificate system in PHP website | PHP scripts

$22



Home Credito loan finance management multipurpose system in PHP

$65




Your Answer

You can post your answer after login..

Live Chat

Hello! How can we assist you today?