Анализируем и сравниваем Выберите одну любую категорию встроенных функции и сравните между собой функции относящиеся к этой категории. Практическая работа в
#include <iostream> #include <cmath> using namespace std; bool prost(int m){ int k = 0; for (int i=2; i<=sqrt(m); i++) if (m % i == 0) k++; return k==0; }
int main(){ int n, r; int i = 1; cout << "n = ", cin >> n, cout << "\n"; if (prost(n)) { cout << "1 * " << n << " = " << n << "\n";} else { r = n; while (r != 1){ i++; if (prost(i)){ while (r % i == 0){ r = r / i; cout << i; if (r != 1) cout << "*"; } } } cout << "=" << n << "\n"; } return 0; }
<?phpif (isset($_GET['a'])) $string_a=htmlentities($_GET['a']);if (isset($_GET['b'])) $string_b=htmlentities($_GET['b']); $isEmpty=false;if ((empty($string_a))&&(empty($string_b))) $isEmpty=true; if ($isEmpty==false){ $a = (int)$string_a; $b = (int)$string_b; $c = $a+$b;}else{ $a = 1; $b = 1;}?><!DOCTYPE html><html lang="ru"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Программа сложения двух чисел</title> </head> <body> <form action="index.php"> <input name="a" type="text" value="<?php echo $a;?>"><br> <input name="b" type="text" value="<?php echo $b;?>"><br> <input type="submit" value="Сложить два числа"><br> </form><?phpif ($isEmpty==false){ echo $a." + ".$b." = ".$c;}?> </body></html>
#include <cmath>
using namespace std;
bool prost(int m){
int k = 0;
for (int i=2; i<=sqrt(m); i++)
if (m % i == 0) k++;
return k==0;
}
int main(){
int n, r;
int i = 1;
cout << "n = ", cin >> n, cout << "\n";
if (prost(n)) {
cout << "1 * " << n << " = " << n << "\n";}
else {
r = n;
while (r != 1){
i++;
if (prost(i)){
while (r % i == 0){
r = r / i;
cout << i;
if (r != 1) cout << "*";
}
}
}
cout << "=" << n << "\n";
}
return 0;
}
Пример:
n = 2720
2*2*2*2*2*5*17=2720