Initial commit
This commit is contained in:
38
cpp/Функции/main.cpp
Normal file
38
cpp/Функции/main.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user