diff --git a/def_loop.py b/def_loop.py new file mode 100644 index 0000000..594f24c --- /dev/null +++ b/def_loop.py @@ -0,0 +1,9 @@ +prices = [40, 30, 50] +def adding(x): + to_pay = 0 + for i in x: + to_pay += i + return to_pay + +print(adding(prices)) + diff --git a/func_loop.js b/func_loop.js new file mode 100644 index 0000000..aa7cb2e --- /dev/null +++ b/func_loop.js @@ -0,0 +1,10 @@ +let prices = [40,30,50]; +function adding(x) { + let to_pay = 0; + for (i of x) { + to_pay += i; + } + return to_pay; +} + +console.log(adding(prices)) diff --git a/func_sum.cpp b/func_sum.cpp new file mode 100644 index 0000000..461437b --- /dev/null +++ b/func_sum.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; +using std::cout; + +int prices[] = { 40, 30, 50 }; + +int adding(int x[], int size) { + int to_pay = 0; + for (int i = 0; i < size; i++) { + to_pay += x[i]; + } + return to_pay; +} + +int main() { + int result = adding(prices, sizeof(prices)); + cout << result; + return 0; +} diff --git a/function.py b/function.py new file mode 100644 index 0000000..95d9e0b --- /dev/null +++ b/function.py @@ -0,0 +1,4 @@ +def main(x, y): + return x + y + +print(main(3, 2)) diff --git a/function_sum.cpp b/function_sum.cpp new file mode 100644 index 0000000..7db0d5b --- /dev/null +++ b/function_sum.cpp @@ -0,0 +1,12 @@ +#include +using namespace std; +using std::cout; + +int sum(int x, int y) { + return x+y; +} + +int main() { + cout << sum(3, 2); + return 0; +} diff --git a/function_sum.js b/function_sum.js new file mode 100644 index 0000000..f63f98e --- /dev/null +++ b/function_sum.js @@ -0,0 +1,5 @@ +function adding(x, y) { + return x + y; +} +let result = adding(3, 2); +console.log(result);