PHP exercises (1), PHP exercises (_PHP tutorial
PHP practice questions (1), PHP practice questions (
Program 1.
Title: The bonus issued by the company is based on the profit. When the profit (I) is less than or equal to 100,000 yuan, the bonus can be increased by 10%; when the profit is more than 100,000 yuan, and less than 200,000 yuan, the portion less than 100,000 yuan will be paid. The commission is 10%, and the commission is 7.5% for the portion above 100,000 yuan; the commission is 5% for the portion above 200,000 yuan between 200,000 and 400,000; the commission is 5% for the portion above 400,000 yuan. 1%, enter the current month’s profit I from the keyboard, what is the total number of bonuses to be distributed? (Use if else if)
<span> 1</span> <span>$I</span> = 4324128<span>; </span><span> 2</span> <span>$bonus</span> = 0; <span>//</span><span> 奖金数</span> <span> 3</span> <span> 4</span> <span>if</span> (<span>$I</span> <= 100000<span>) { </span><span> 5</span> <span>$bonus</span> = <span>$I</span> * 1/10<span>; </span><span> 6</span> } <span>else</span> <span>if</span> (<span>$I</span> > 100000 && <span>$I</span> < 200000<span>) { </span><span> 7</span> <span>$bonus</span> = <span>$I</span> % 100000 * 7.5/100 + (<span>$I</span> - <span>$I</span> % 100000) * 1/10<span>; </span><span> 8</span> } <span>else</span> <span>if</span> (<span>$I</span> >= 200000 && <span>$I</span> < 400000<span>) { </span><span> 9</span> <span>$bonus</span> = (<span>$I</span> - 200000) * 5/100 + (<span>$I</span> % 100000 * 7.5/100) + (<span>$I</span> - <span>$I</span> % 100000) * 1/10<span>; </span><span>10</span> } <span>else</span><span> { </span><span>11</span> <span>$bonus</span> = (<span>$I</span> - 400000) * 1/100 + (<span>$I</span> - 200000) * 5/100 + (<span>$I</span> % 100000 * 7.5/100) + (<span>$I</span> - <span>$I</span> % 100000) * 1/10<span>; </span><span>12</span> <span>} </span><span>13</span> <span>14</span> <span>echo</span> 'bonus :' . <span>$bonus</span>.'<br/>';
Program 2.
Title: Enter three integers x, y, z and find the largest number;
<span>1</span> <span>$x</span> = 4<span>; </span><span>2</span> <span>$y</span> = 7<span>; </span><span>3</span> <span>$z</span> = 2<span>; </span><span>4</span> <span>5</span> <span>$max</span> = <span>$x</span>><span>$y</span> ? <span>$x</span> : <span>$y</span><span>; </span><span>6</span> <span>$max</span> = <span>$z</span>><span>$max</span> ? <span>$z</span> : <span>$max</span><span>; </span><span>7</span> <span>8</span> <span>echo</span> 'max number :' . <span>$max</span> .'<br/>';
Program 3.
Title: Print out all the "daffodil numbers". The so-called "narcissus number" refers to a three-digit number A number whose sum of cubes is equal to the number itself.
<span> 1</span> <span>$j</span> = 0; <span>//</span><span> 数的个位 </span> <span> 2</span> <span>$k</span> = 0; <span>//</span><span> 数的十位</span> <span> 3</span> <span>$l</span> = 0; <span>//</span><span> 数的百位</span> <span> 4</span> <span>for</span>(<span>$i</span> = 100; <span>$i</span><1000; <span>$i</span>++<span>){ </span><span> 5</span> <span>$j</span> = <span>$i</span> % 10<span>; </span><span> 6</span> <span>$k</span> = (<span>$i</span> % 100 - <span>$j</span>) / 10<span>; </span><span> 7</span> <span>$l</span> = (<span>$i</span> - <span>$i</span> % 100) / 100<span>; </span><span> 8</span> <span>if</span> (<span>$i</span> == (<span>$j</span>*<span>$j</span>*<span>$j</span> + <span>$k</span>*<span>$k</span>*<span>$k</span> + <span>$l</span>*<span>$l</span>*<span>$l</span><span>)) { </span><span> 9</span> <span>echo</span> <span>$i</span> . ' '<span>; </span><span>10</span> <span> } </span><span>11</span> }
Program 4.
Title: Monkey eating peach problem: The monkey picked a few peaches on the first day, ate half of them immediately, and then Not satisfied, I ate another peach, and the next morning I ate half of the remaining peaches and ate another one. From then on, every morning I ate half and one of the leftovers from the previous day. When I wanted to eat more on the morning of the 10th day, there was only one peach left. Find out how many were picked on the first day. (Use reverse thinking and push forward from back)
<span>1</span> <span>$sum</span> = 1<span>; </span><span>2</span> <span>for</span> (<span>$i</span> = 1; <span>$i</span> <= 10; <span>$i</span>++<span>) { </span><span>3</span> <span>$sum</span> = (<span>$sum</span> + 1) * 2<span>; </span><span>4</span> <span>} </span><span>5</span> <span>echo</span> '桃子总数:' .<span>$sum</span>. '<br/>';
Program 5.
Question: There is a sequence of fractions: 2/1, 3/2, 5/3, 8/5, 13 /8, 21/13... Find the sum of the first 20 terms of this sequence. (Pay attention to the changing rules of the numerator and denominator)
<span>1</span> <span>$sum2</span> = 0<span>; </span><span>2</span> <span>$a</span> = 2<span>; </span><span>3</span> <span>$b</span> = 1<span>; </span><span>4</span> <span>for</span>(<span>$i</span> = 1; <span>$i</span> <= 20; <span>$i</span>++<span>) { </span><span>5</span> <span>$sum2</span> = <span>$sum2</span> + <span>$a</span>/<span>$b</span><span>; </span><span>6</span> <span>$b</span> = <span>$a</span><span>; </span><span>7</span> <span>$a</span> += <span>$b</span><span>; </span><span>8</span> <span>} </span><span>9</span> <span>echo</span> '前20项之和为:' .<span>$sum2</span>.'<br/>';

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

In this chapter, we are going to learn the following topics related to routing ?

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.
