Heim > Backend-Entwicklung > PHP-Tutorial > PHP练习题(一),PHP练习题(_PHP教程

PHP练习题(一),PHP练习题(_PHP教程

WBOY
Freigeben: 2016-07-12 08:54:15
Original
2828 Leute haben es durchsucht

PHP练习题(一),PHP练习题(

程序1 .
题目: 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10% ; 利润高于10 万元, 低于20 万元时, 低于10万元的部分按10% 提成,高于 10万元的部分,可提成7.5%;20万到40 万之间时,高于20 万元的部分,可提成5%; 高于40 万元的部分, 可提成1%,从键盘输入当月利润I,求应发放奖金总数?(利用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/>';
Nach dem Login kopieren

程序2.
题目: 输入三个整数x, y, z, 找出最大的数;

<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/>';
Nach dem Login kopieren

程序3.
题目: 打印出所有的“水仙花数”, 所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。

<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> }
Nach dem Login kopieren

程序4.
题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾,又吃了一个,第二天早上又将剩下的桃子吃掉一半,又多吃了一个。 以后每天早上都吃了前一天剩下的一半零一个。到第10天早上想再吃时,只剩下一个桃子了。求第一天共摘了多少。 (采用逆向思维,从后往前推)

<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/>';
Nach dem Login kopieren

程序5.
题目: 有一分数序列: 2/1, 3/2, 5/3, 8/5, 13/8, 21/13...求出这个数列的前20项之和。(注意分子和分母的变化规律)

<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/>';
Nach dem Login kopieren

 


 
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1120385.htmlTechArticlePHP练习题(一),PHP练习题( 程序1 . 题目: 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10% ; 利润高于10 万元,...
Verwandte Etiketten:
php
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage