38 lines
762 B
C++
Executable File
38 lines
762 B
C++
Executable File
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
/* Синтаксис:
|
|
возвращаемый_тип имя(тип_параметра параметр, ...) {
|
|
return значение;
|
|
}
|
|
*/
|
|
|
|
int timesTwo(int num) {
|
|
return num * 2;
|
|
}
|
|
|
|
void printNum(int num) {
|
|
cout << num << endl;
|
|
}
|
|
|
|
double squareroot(double n) {
|
|
/**
|
|
Метод Ньютона
|
|
*/
|
|
double root = n / 2;
|
|
|
|
for (int i = 0; i < 20; i++) {
|
|
cout << "Guess " << i << " root " << root << endl;
|
|
root = (.5) * (root + (n / root));
|
|
}
|
|
|
|
return root;
|
|
}
|
|
|
|
int main() {
|
|
int res = timesTwo(5); // Вызов функции, возвращающей значение
|
|
printNum(res); // Вызов функции, не возвращающей значение
|
|
cout << squareroot(9) << endl;
|
|
return 0;
|
|
} |