Files
learning/cpp/Функции/main.cpp
2022-04-28 04:34:45 +03:00

38 lines
762 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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;
}