Files
learning/Programming Notes/cpp/Функции/main.cpp
T
oleg20111511 f235a35ebb Reorganize
2026-03-02 19:15:17 +02:00

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;
}