Created
April 7, 2025 08:43
-
-
Save vlaleli/b1452a778b4eeb8395bc50fb84f5ee08 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1) | |
| #include <iostream> | |
| using namespace std; | |
| double add(double a, double b) { return a + b; } | |
| double subtract(double a, double b) { return a - b; } | |
| double multiply(double a, double b) { return a * b; } | |
| double divide(double a, double b) { return b != 0 ? a / b : 0; } | |
| int main() { | |
| double (*operations[])(double, double) = { add, subtract, multiply, divide }; | |
| char symbols[] = { '+', '-', '*', '/' }; | |
| double a, b; | |
| char op; | |
| cout << "Введіть вираз: "; | |
| cin >> a >> op >> b; | |
| for (int i = 0; i < 4; i++) { | |
| if (op == symbols[i]) { | |
| cout << "Результат: " << operations[i](a, b) << endl; | |
| break; | |
| } | |
| } | |
| return 0; | |
| } | |
| 2) | |
| #include <iostream> | |
| using namespace std; | |
| void sumArrays(const int* A, const int* B, int* C, int size) { | |
| for (int i = 0; i < size; i++) { | |
| C[i] = A[i] + B[i]; | |
| } | |
| } | |
| int main() { | |
| const int SIZE = 5; | |
| int A[SIZE] = {1, 2, 3, 4, 5}; | |
| int B[SIZE] = {5, 4, 3, 2, 1}; | |
| int C[SIZE]; | |
| sumArrays(A, B, C, SIZE); | |
| cout << "Масив C: "; | |
| for (int i = 0; i < SIZE; i++) { | |
| cout << C[i] << " "; | |
| } | |
| cout << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment