-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zadachnik_Abramyan_part9 SeriesSeries.php
383 lines (369 loc) · 7.5 KB
/
Zadachnik_Abramyan_part9 SeriesSeries.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<?php
/**
* @author Valera
* @copyright 2017
*/
function randomm()
{
static $x = 133;
$p = 3156353;
$x = ($x*$x + 3) % $p;
//print($x." ");
return abs($x / $p);
}
function random2($a, $b)
{
return (int)($a + randomm()*($b-$a));
}
/*for($i=0; $i<100; $i++)
print(random2(10,100)."<br>");
*/
function f1($x)
{
$x += 2; // changed parameter
print($x."<br>");
}
function f2()
{
$x = 4;
f1($x); //nothing changed x
print($x."<br>"); // but not argument
$x++;
$z = print($x."<br>");
print("dddddd ".$z."<br>");
}
//f2();
function sum($a, $b)
{
return $a+$b;
}
//print(sum(5,11)."<br>");
function _abs($a)
{
return $a>0 ? $a : -$a;
}
function sign($x)
{
if($x<0) return -1;
if($x==0) return 0;
return 1;// íå íóæåí íè if íè else
}
function Proc16()
{
$a=-3*lcg_value();
$b=1.7*lcg_value();
$S=sign($a)+sign($b);
print("******** Proc16() *********<br>");
print("a=".$a." b=".$b." S=".$S."<br>");
}
//Proc16();
function Proc16b()
{
$x=rand(-10,10);
if($x<0) $y=-1;
elseif($x==0) $y=0;
else $y=1;
print("Sign(x):<br>");
print("x=".$x." y=".$y."<br>");
}
//Proc16b();
function Proc16c()
{
print("*********** Proc16c() switch()**********<br>");
$x=rand(-10,10);
switch($x)
{
case -10:
case -9:
case -8:
case -7:
case -6:
case -5:
case -4:
case -3:
case -2:
case -1:
$y=-1;
break;
case 0:
$y=0;
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
$y=1;
break;
default: print("Error.<br>");
}
print("Sign(".$x.")=".$y."<br>");
}
//Proc16c();
function Proc16d()
{
print("*********** Proc16d() x ? y : z**********<br>");
$x=rand(-10,10);
$y=$x < 0 ? -1: 1;
print("x=".$x."<br>");
print("y=".$y."<br>");
/*$x=-17;
$x=$x<0 ? -$x : $x;
print("x=".$x."<br>");
**/
}
//Proc16d();
function Proc16e()
{
print("*********** Proc16e() Ôóíêöèÿ Õåâèñàéäà. x ? y : z**********<br>");
$t=rand(-10,10);
$nt=$t < 0 ? 0: 1;
print("t=".$t." n(t)=".$nt."<br>");
print("t<0: n(t)=0; t>=0: n(t)=1<br>");
}
//Proc16e();
function Proc34()
{
print("********* Proc16(): Factorial ********<br>");
$n=rand(-10,10);
$F=1;
$i=0;
do
{
$i++;
$F*=$i;
if($i>=$n)
{
$save=$F;
break;
}
print("i=".$i." Fact=".$F."<br>");
}
while(true);
print($n."!=".$save."<br>");
}
//Proc34();
function Proc34a()
{
print("********* Proc16a(): Factorial while do********<br>");
$n=rand(0,10);
$F=1;
$i=0;
while(true)
{
$i++;
$F*=$i;
if($i>=$n)
{
$save=$F;
break;
}
print("i=".$i." Fact=".$F."<br>");
}
print($n."!=".$save."<br>");
}
//Proc34a();
function Proc35x()
{
print("abs(x)<br>");
$x=rand(-2,2);
$y= $x<0 ? -$x : $x;
print("x=".$x." abs(x)=".$y."<br>");
}
//Proc35x();
function ProcABS($a)
{
if($a<0) $a=-$a;
else $a=$a;
return $a;
}
//print(ProcABS(5)."<br>");
function ProcMath()
{
print("******* Math ********<br>");
print(M_PI."<br>");
print(pi()."<br>");
$x=M_PI_2;
$y=M_PI_4;
$z=exp(1);
$tay=rand(-3,3);
$t=abs($tay);
print($x." ".$y." ".$z." ".$tay." abs(tay)=".$t."<br>");
$a=3.6;
$b=round($a);
print("a=".$a." round(a)=".$b."<br>");
$arr=array(M_PI, M_E, M_LOG2E, M_LOG10E, M_LN2, M_LN10, M_PI_2, M_PI_4, M_1_PI, M_2_PI, M_SQRTPI, M_SQRT2, M_SQRT3, M_SQRT1_2, M_LNPI, M_EULER);
echo "<pre>";
print_r($arr);
echo "</pre>";
$var=" element of array";
$arr=(array)$var;
echo "<pre>";
print_r($arr);
echo "</pre>";
print(" FF îêðóãëåíèÿ: <br>");
echo abs(-4.5)."<br>";
echo abs(6)."<br>";
echo round(4.4)."<br>";
echo round(3.5)."<br>";
echo round(3.6)."<br>";
echo round(3.6, 0)."<br>";
echo round(1.95583,2)."<br>";
echo round(5.042,2)."<br>";
echo round(5.055,2)."<br>";
print(" Îñòàòîê îò äåëåíèÿ: <br>");
echo fmod(10,3)."<br>";
echo fmod(5.7, 1.3)."<br>";
print(" Ñðàâíèì fmod è %<br>");
$x1=fmod(9,2);
$x2=(9%2);
print("fmod(10,3)=".$x1."<br>");
print("10%3=".$x2."<br>");
print(" Ëîãàðèôìè÷åñêèå è ñòåïåííûå ff<br>");
$x3=pow(2,8);
$x4=pow(2, 1.3);
$x4=pow(2, -1);
$x5=pow(0,0);
$x6=pow(-1,10);
$x6=exp(2);
print("x3=".$x3." x4=".$x4." x5=".$x5." x6=".$x6."<br>");
}
//ProcMath();
function Summa1($x,$y)
{
$S=$x+$y;
print("x+y=".$x."+".$y."=".$S."<br>");
}
//Summa1(1,2);
function Ocrug()
{
$x1=rand(-5,2);
$x2=7*lcg_value();
$x3=rand(-2,7);
$y1=abs($x1);
$y2=round($x2);
$y3=fmod($x1,$x3);
$y4=$x1%$x3;
$y6=abs($x3);
//$y5=hypot($y4,$y6);
$y5=hypot(3,7);
print(" ******** ff îêðóãëåíèÿ ************<br>");
print("abs(".$x1.") = ".$y1."<br>");
print("round(".$x2.") = ".$y2."<br>");
print("fmod(".$x1.",".$x3.") = ".$y3."<br>");
print($x1."%".$x3."=".$y4."<br>");
//print(" òðåòüÿ ñòîðîíà òðåóãîëüíèêà ".$y1." ".$y6." áóäåò ".$y5."<br>");
print(" òðåòüÿ ñòîðîíà òðåóãîëüíèêà áóäåò ".$y5."<br>");
}
//Ocrug();
// Êóçíåöîâ ïðèìåðû Ãëàâà 7 Ôóíêöèè
function get_sum()
{
$sum=10+5;
return $sum;
}
echo get_sum(10,5);
print("<br>");
function get_sum2()
{
$sum=10+5;
echo $sum;
}
get_sum2(10,5);
print("<br>");
//Îáúÿâëÿåì ëîãè÷åñêóþ ïåðåìåííóþ
$flag=true;
// Åñëè ïåðåìåííàÿ $flag ðàâíà TRUE, îáúÿâëÿåì ôóíêöèþ
if($flag)
{
function get_sum3()
{
$sum=10+5;
echo $sum;
}
}
// Dspsdftv ôóíêöèþ, åñëè ïåðåìåííàÿ $flag ðàâíà TRUE
if($flag) get_sum3();// 15
print("<br>");
function get_sum4($left,$right)
{
$sum=$left+$right;
echo $sum;
}
get_sum4(10,5);// 15
print("<br>");
function funct($left,$middle,$right)
{
echo $left."<br>";
echo $middle."<br>";
echo $right."<br>";
}
$i=10;
funct(++$i, $i=$i*2, --$i);
print(" ïåðåäà÷à àðãóìåíòà ïî çíà÷åíèþ <br>");
function get_sum5($var) // àðãóìåíò ïåðåäàåòñÿ ïî çíà÷åíèþ
{
$var=$var+5;
return $var;
}
$new_var=20;
echo get_sum5($new_var);
echo "<br>$new_var";
print("<br>");
print(" ïåðåäà÷à àðãóìåíòà ïî ññûëêå <br>");
function get_sum6(&$var) // àðãóìåíò ïåðåäàåòñÿ ïî ññûëêå
{
$var=$var+5;
return $var;
}
$new_var=20;
echo get_sum6($new_var);
echo "<br>$new_var";
// Ñòàòè÷åñêèå ïåðåìåííûå
print("<br>");
print("Ñòàòè÷åñêèå ïåðåìåííûå<br>");
function Counter()
{
$counter=0;
return ++$counter;
}
echo Counter()."<br>";
/*
function Counter1()
{
static $counter=0;
return ++$counter;
}
echo Counter1()."<br>";
**/
// Âîçâðàò ìàññèâà ôóíêöèåé
function format_size($byte)
{
$kbyte=$byte/1024;
$mbyte=$kbyte/1024;
$gbyte=$kbyte/1024;
return array($byte,$kbyte,$mbyte,$gbyte);
}
list($byte,$kbye,$mbyte,$gbyte)=format_size(38592859);
// Ðåêóðñèâíûå ôóíêöèè
print("Ðåêóðñèâíûå ôóíêöèè<br>");
function callself($counter)
{
// Åñëè ïàðàìåòð $counter áîëüøå, ïðîäîëæàåì ðåêóðñèâíûé ñïóñê
if($counter>0)
{
// Óìåíüøàåì çíà÷åíèå ïàðàìåòðà $counter è âûâîäèì åãî çíà÷åíèå â îêíî áðàóçåðà
echo($counter--)."<br>";
callself($counter);
}
// Åñëè çíà÷åíèå ïàðàìåòðà ìåíüøå èëè ðàâíî 0, ïðåêðàùàåì ðåêóðñèâíûé ñïóñê
else return;
}
// Âûçûâàåì ôóíêöèþ callself()
callself(4);
?>