
Даю 40 балів!!! Visual Studio 2019Мова програмування С++1. Задано натуральне число n і дійсні
числа b1,b2,...bn. Визначити суму тих дійсних чисел які більше p.2. Дано натуральне число n. отримати послідовність a1,a2,...an , яка утворюється згiдно з законом: a0 = 1 ; ak=ka(k-1) +1/k ( k =1,2...)3. Задано натуральнi числа х i у. Обчислити добуток х*у, використовуючи лише операцію складання. Завдання вирішити двома способами.

Ответы на вопрос

Завдання 1:
#include <iostream>
using namespace std;
int Task1()
{
int n, p;
cout << "Введіть кількість елементів масиву: ";
cin >> n;
cout << "Введіть число p: ";
cin >> p;
int *arr = new int[n];
for (int i = 0; i < n; i++)
{
cout << "Введіть " << i + 1 << " елемент масиву: ";
cin >> arr[i];
}
int sum = 0;
for (int i = 0; i < n; i++)
{
if (arr[i] > p)
{
sum += arr[i];
}
}
cout << "Сума елементів масиву, які більші за p: " << sum << endl;
delete[] arr;
return 0;
}
Завдання 2:
#include <iostream>
using namespace std;
int Task2()
{
int n;
cout << "Введіть кількість елементів масиву: ";
cin >> n;
double *arr = new double[n];
arr[0] = 1;
for (int i = 1; i < n; i++)
{
arr[i] = i * arr[i - 1] + 1 / i;
}
for (int i = 0; i < n; i++)
{
cout << "a" << i + 1 << ": " << arr[i] << endl;
}
delete[] arr;
return 0;
}
Завдання 3:
#include <iostream>
using namespace std;
int Task3()
{
int x, y;
cout << "Введіть число x: ";
cin >> x;
cout << "Введіть число y: ";
cin >> y;
int sum = 0;
for (int i = 0; i < y; i++)
{
sum += x;
}
cout << "Сума: " << sum << endl;
return 0;
}



Task 1: Finding the sum of real numbers greater than p
To find the sum of real numbers greater than p, given a natural number n and real numbers b1, b2, ..., bn, you can follow these steps:
1. Initialize a variable `sum` to 0. 2. Iterate over each real number `b` in the given list of numbers. 3. Check if `b` is greater than p. 4. If `b` is greater than p, add `b` to the `sum`. 5. After iterating over all the numbers, the `sum` will contain the sum of real numbers greater than p.
Here's an example implementation in C++:
```cpp
#include
int main() {
int n;
double p;
std::vector
// Read the values of n, p, and the list of numbers std::cout << "Enter the value of n: "; std::cin >> n;
std::cout << "Enter the value of p: "; std::cin >> p;
std::cout << "Enter " << n << " real numbers: "; for (int i = 0; i < n; i++) { double num; std::cin >> num; numbers.push_back(num); }
// Calculate the sum of real numbers greater than p double sum = 0; for (double b : numbers) { if (b > p) { sum += b; } }
// Output the result std::cout << "The sum of real numbers greater than " << p << " is: " << sum << std::endl;
return 0; } ```
Please note that this is just an example implementation. You can modify it according to your specific requirements.
Task 2: Generating a sequence according to the given law
To generate a sequence `a1, a2, ..., an` according to the law `a0 = 1; ak = ka(k-1) + 1/k (k = 1, 2...)`, you can follow these steps:
1. Initialize a variable `a` to 1. 2. Initialize an empty list `sequence`. 3. Append `a` to the `sequence`. 4. Iterate from `k = 1` to `n`. 5. Calculate the value of `a` using the given law: `a = k * a * (a - 1) + 1 / k`. 6. Append the calculated `a` to the `sequence`. 7. After the iteration, the `sequence` will contain the desired sequence `a1, a2, ..., an`.
Here's an example implementation in C++:
```cpp
#include
int main() {
int n;
std::vector
// Read the value of n std::cout << "Enter the value of n: "; std::cin >> n;
// Generate the sequence double a = 1; sequence.push_back(a); for (int k = 1; k <= n; k++) { a = k * a * (a - 1) + 1.0 / k; sequence.push_back(a); }
// Output the sequence std::cout << "The sequence is: "; for (double num : sequence) { std::cout << num << " "; } std::cout << std::endl;
return 0; } ```
Again, please note that this is just an example implementation. You can modify it according to your specific requirements.
Task 3: Computing the product of x and y using only addition
To compute the product of two natural numbers x and y using only the addition operation, you can follow these steps:
1. Initialize a variable `product` to 0. 2. Iterate `y` times. 3. Add `x` to the `product` in each iteration. 4. After the iteration, the `product` will contain the desired product of x and y.
Here's an example implementation in C++:
```cpp
#include
int main() { int x, y;
// Read the values of x and y std::cout << "Enter the value of x: "; std::cin >> x;
std::cout << "Enter the value of y: "; std::cin >> y;
// Compute the product of x and y using only addition int product = 0; for (int i = 0; i < y; i++) { product += x; }
// Output the result std::cout << "The product of " << x << " and " << y << " is: " << product << std::endl;
return 0; } ```
Once again, please note that this is just an example implementation. You can modify it according to your specific requirements.
I hope this helps! Let me know if you have any further questions.


Похожие вопросы
Топ вопросов за вчера в категории Информатика
Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili