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/>';