Welcome to Techno Smarter QA, Question, Answer forum. Ask questions, receive answers, or help someone. Join Now
+3 votes

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.

in PHP by (2k points) 8 18 40

1 Answer

0 votes

PHP programming is based on operators and operands. If you are already learned operators in C language, you will understand easily. You can use mathematics formula (a+b) in 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  


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


if a=2 and b=4



= 4+16+16


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 –



Use the above mathematics login –


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


//change values according your need



echo "(a+b)<sup>2</sup>=a<sup>2</sup>+b<sup>2</sup>+2ab";




echo "=".$result;


You will get the result as output –



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

by (9.1k points) 11 25 63