Table of Contents
PHP practice questions (1), PHP practice questions (
Home Backend Development PHP Tutorial PHP exercises (1), PHP exercises (_PHP tutorial

PHP exercises (1), PHP exercises (_PHP tutorial

Jul 12, 2016 am 08:54 AM
php

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/>';
Copy after login

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/>';
Copy after login

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> }
Copy after login

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/>';
Copy after login

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/>';
Copy after login



www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1120385.htmlTechArticlePHP practice questions (1), PHP practice questions (Procedure 1. Question: The bonuses issued by the company are based on profits. 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,...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

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

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

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

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

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

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

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

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

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

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

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

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

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

See all articles