-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.9.php
43 lines (35 loc) · 1 KB
/
1.9.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
<html>
<head>
</head>
<body>
<FORM action="1.9.php" method="GET">
<input type="text" placeholder="Podaj liczby naturalne oddzielone spacjami" name="numbers1">
<input type="text" placeholder="Podaj liczby naturalne oddzielone spacjami" name="numbers2">
<input type="submit" value="Policz iloczyn skalarny" name="submit">
</FORM>
<?php
$numbers1= $_GET['numbers1'];
$numbers2= $_GET['numbers2'];
if($numbers1 != null && $numbers2 != null){
$array1 = array();
$array2 = array();
$array1 = array_map('intval', explode(' ', $numbers1));
$array2 = array_map('intval', explode(' ', $numbers2));
if(count($array1) == 0 || count($array2) == 0){
echo ("BŁĄD");
return;
}
if(count($array1) < count($array2)){
$min_count = count($array1);
}else{
$min_count = count($array2);
}
$scalar = 0;
for ($i = 0; $i < $min_count; $i++) {
$scalar += $array1[$i] * $array2[$i];
}
echo "Iloczyn skalarny: " . $scalar;
}
?>
</body>
</html>