(PHP implementation) Use only ++ operations to implement addition, subtraction, multiplication, and division

Addition The code is as follows:function jiafa($a,$b){ for($ i=0;$i<$b;$i++) { $a++;} return $a;}//echo jiafa(4,2) ;Subtraction The code is as follows:function jianfa($a,$b) { $c=0; while($b!=$a) { $b++; $c++; } echo $c;} // end func//jianfa(10,3);multiplication code As follows:function chengfa($a,$b){ $c=0; for($j=0;$j<$b;$j++) { $c=jiafa($c,$a); } return $c;} // end func//chengfa(9,3);Division The code is as follows:function chufa($d,$e){ $k =0; $f=0; while($f<$d) { $k++; $f=chengfa($e,$k); } return $k;} // end funcecho chufa(16,2);

Simple implementation of addition, subtraction, multiplication and division calculator with php

Use php to realize addition, subtraction, multiplication and division calculator. The code is very simple! The code is as follows: <?php header(“content-type:text/html;charset=utf-8”); session_start(); ?> The first number Calculation symbol + – * / The second number <?php $num1=$_POST[‘num1’]; $num2=$_POST [‘num2’]; $oper=$_POST[‘oper’]; $rs=0; switch($oper){ case “+”: $rs =$num1+$num2; break; case “-“: $rs=$num1-$num2; break; case “*”: $rs= $num1*$num2; break; case “/”: $rs=$num1/$num2; break; default: echo “Your input is incorrect”; } $_SESSION[‘rs’]=$rs; echo ‘Evaluation result is: ‘.$_SESSION[‘rs’]; ?>

PHP’s chr and ord functions implement character addition, subtraction, multiplication, and division operations to achieve code

The chr function is used to convert ASCII codes to charactersord function is used to convert characters to ASCII codes ASCII codes are the codes of characters that can be displayed by the computer, and its value range is 0-255. These include punctuation, letters, numbers, Chinese characters, etc. In the programming process, the specified characters are often converted into ASCII codes for comparison. The following is the function provided by PHP to convert ASCII codes and characters. 1. chr() function This function is used to convert the ASCII code value into a string. Its function is declared as follows: string chr (int ascii); 2. ord() function This function is used to convert a string into an ASCII code value. Its function declaration is as follows: int ord(string str); Example: Use the chr() function and ord() function to perform conversion operations between strings and ASCII codes, and the program code is as follows: The code is as follows: <?php $str1=chr(88); echo $str1; //The return value is X $str2=chr(ord(X)+1); // echo $str2; //The return value is Y echo “\t”; $str3=ord(‘S’ ); echo $str3; //The return value is 83 ?> Operation result: X Y 83

How to use ThinkPHP3.2.3 to realize addition, subtraction, multiplication and division picture verification code

Today, I will talk to you about how to use ThinkPHP 3.2.3 to realize the verification code of addition, subtraction, multiplication and division. Many people may not understand it well. In order to let everyone know better, the editor summarizes the following for you I hope you can gain something from this article. VerifyProcess.class.php: imageW || $this->imageW = $this->length*$this->fontSize*1.5 + $this->length*$this->fontSize/2; // image height (px) $this->imageH || $this->imageH = $this->fontSize * 2.5; // Create an image of $this->imageW x $this->imageH $this->_image = imagecreate($this->imageW, $this->imageH); the // set the background imagecolorallocate($this->_image, $this->bg[0], $this->bg[1], $this->bg[2]); the // Random color of verification code font $this->_color = imagecolorallocate($this->_image, mt_rand(1,150), mt_rand(1,150), mt_rand(1,150)); // The verification code uses a random font $ttfPath = $_SERVER['DOCUMENT_ROOT'].'/ThinkPHP/Library/Think/Verify/' .  ($this->useZh ? 'zhttfs' : 'ttfs') . '/'; the if(empty($this->fontttf)){ $dir = dir($ttfPath); $ttfs = array(); while (false !== ($file = $dir->read())) { if($file[0] != '.' && substr($file, -4) == '.ttf') { $ttfs[] = $file; } } $dir->close(); $this->fontttf = $ttfs[array_rand($ttfs)]; } $this->fontttf = $ttfPath . $this->fontttf; the if($this->useImgBg) { $this->_background(); } the if ($this->useNoise) { // paint dots $this->_writeNoise(); } if ($this->useCurve) { // Draw interference lines $this->_writeCurve(); } the // Draw verification code $codeNX = 0; // The left margin…

Addition, subtraction, multiplication and division, area calculation, small cases of printing pyramids and processing methods of oblique pyramids [php entry]

Addition, subtraction, multiplication and division, area calculation, small cases of printing pyramids and processing methods of oblique pyramids [php entry]

In this case, html js php loop control is used, knowledge related to logical judgment: When reviewing the loop control language and for loop printing pyramid today, The displayed pyramid is always screwed up in the browser, and Firefox, IE, and Chrome display incorrectly. After checking, I think it should be a problem with the character set, but after modifying the character set, it still doesn’t work Yes, it was later discovered that the utf-8 font space problem occupies two characters of space, the following are the replacement methods of some spaces I collected:   character width)    half blank (1 character width)     one blank (2 character width)    narrow blank (less than 1 character width) ? You can use a name or number as a substitute for a space, the name must be lowercase, and the “;” at the end cannot be omitted. Click me to view the case

How to use PHP to implement simple addition, subtraction, multiplication and division

This article mainly explains “how to use PHP to realize simple addition, subtraction, multiplication and division”. Let’s study and learn “how to implement simple addition, subtraction, multiplication and division with PHP”! The focus of this article is how to create a PHP class to implement addition, subtraction, multiplication and division between two numbers, which is similar to a very simple calculator function. It is very simple to implement, continue to look down: Here is a brief introduction to the constructor and the definition of private and public: Constructor It is a special method, which is mainly used to initialize the object when creating the object, that is, to assign the initial value to the object member variable, and it is always used together with the new operator in the object creation statement. private means private, this keyword represents a private class member, that is, it can only be accessed by the class where it is defined. As in the above example, we declare a method that declares a private one. public means public: public class members can be accessed anywhere. Example First open the PHP editor and create a PHP sample file class MyCalculator { the private $_fval, $_sval; the…

Simple implementation of addition, subtraction, multiplication and division calculator with php

The first number calculation symbol + – * / Second number <?php $num1 = $_POST['num1']; $num2 = $_POST['num2'] ;$oper = $_POST['oper'];$rs = 0; switch ($oper) { case "+": $rs = $num1 + $num2; break; case "-": $ rs = $num1 – $num2; break; case "*": $rs = $num1 * $num2; (, the source of this article is gao@!dai!ma.com engaged in $$ code ^@code network*Code for gaodaima break; case “/”: $rs = $num1 / $num2; break; default: echo “Your input is incorrect”;}$_SESSION['rs& #039;] = $rs; echo ' evaluates to: ' . $_SESSION['rs'];?>

Use PHP language to make a simple calculator with functions of addition, subtraction, multiplication and division

Preparation: Environment: PHPStudy Open Apache and Mysql Open code editor + – * / % Running result: (take 3+5 as an example)

PHP realizes addition, subtraction, multiplication and division picture verification code, ThinkPHP3.2.3 realizes addition, subtraction, multiplication and division picture verification code

The verification code class that comes with ThinkPHP 3.2.3 is located at /ThinkPHP/Library/Think/Verify.class.php, The font file is located at /ThinkPHP/Library/Think/Verify/ You can find it in Modify in the Verify.class.php file,You can also write a separate class to inherit the verification code class that comes with it. If you write an inherited class alone & #xff0c; you can reuse the properties and methods of the parent class & # xff0c; but it should be noted that some properties and methods in the parent class are private (private) & # xff0c; you can modify these private Attributes and methods are protected (protected) , If you do not want to modify the methods that come with the framework, you can also define these attributes and methods in subclasses. The test controller is located at /Application/Home/Controller/TestVerifyController.class.php The test view is located at /Application/Home/View/User/verify.html The custom subclass is located at /Application/Home/Common/VerifyProcess.class.php VerifyProcess.class.php: namespace Home\Common; use Think\Verify; class VerifyProcess extends Verify { private $_image = NULL; // verification code image example private $_color = NULL; // Captcha font color public function entryProcess($id = '') { / / Image width (px) $this->imageW || $this->imageW = $this->length*$this->fontSize*1.5 + $this->length*$this->fontSize/2; // image height (px) $this->imageH || $this->imageH = $this->fontSize…

PHP’s chr and ord functions implement character addition, subtraction, multiplication, and division operations to achieve code_PHP

The chr function is used to convert ASCII codes to charactersThe ord function is used to convert characters to ASCII codes ASCII codes are the codes that computers can display characters, and its value range is 0-255, including punctuation, letters, numbers, Chinese characters, etc. In the programming process, the specified characters are often converted into ASCII codes for comparison. The following is the function provided by PHP to convert ASCII codes and characters. 1. chr() function This function is used to convert the ASCII code value into a string. Its function is declared as follows: string chr (int ascii); 2. ord() function This function is used to convert a string into an ASCII code value. Its function declaration is as follows: int ord(string str); Example: Use chr() function and ord() function to perform the conversion operation between string and ASCII code, the program code is as follows: The code is as follows: <?php $str1=chr(88); echo $str1; //The return value is X $str2=chr( ord(X)+1); // echo $str2; //The return value is Y echo “\t”; $str3=ord(from 4 source gaodaimacom 做#代 %code*netGaodaima code‘S’); echo $str3; //The return value is 83 ?> Running result: X Y 83

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索