• Register
Welcome to Techno Smarter QA, Questions, Answers Community
Welcome to Techno Smarter Q&A, where you can ask questions and receive answers from other members of the community. Ask the tech & programming Question that you want. Guests Posting are allowed.
+2 votes
6 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.

in PHP by (1.8k points) 1 5 26

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  

(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

//change values according your need

$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.

by (7.1k points) 4 21 46
...