Вопрос задан 04.08.2018 в 17:18. Предмет Информатика. Спрашивает Бакатов Талгат.

Допоможіть будь ласка скласти программу С++.Дано групу з N цілих чисел. Дані знаходяться в

текстовому файлі (в першому рядку число N,в наступних N рядках-по одному цілому числу).Знайти добуток від'ємних чисел. Перевірити,чи буде добуток від'ємним?
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Волков Михаил.
Через проблеми сервісу відповідь тут: https://www.dropbox.com/s/jpqf3v0u6frz0yx/1.cpp?dl=0
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Program in C++ to find the product of negative numbers in a group of integers

Here's a program in C++ that reads a group of integers from a text file and finds the product of the negative numbers. It also checks whether the product will be negative or not.

```cpp #include #include

int main() { std::ifstream inputFile("input.txt"); // Assuming the input file is named "input.txt" int N; inputFile >> N; // Read the value of N from the first line of the file

int number; int product = 1; bool hasNegative = false;

for (int i = 0; i < N; i++) { inputFile >> number; // Read each number from the file

if (number < 0) { product *= number; // Multiply the negative number with the product hasNegative = true; } }

inputFile.close(); // Close the input file

if (hasNegative) { std::cout << "The product of the negative numbers is: " << product << std::endl;

if (product < 0) { std::cout << "The product is negative." << std::endl; } else { std::cout << "The product is not negative." << std::endl; } } else { std::cout << "There are no negative numbers in the group." << std::endl; }

return 0; } ```

This program uses an input file named "input.txt" to read the group of integers. The first line of the file contains the value of N, which represents the number of integers in the group. The subsequent N lines contain one integer each.

The program reads each integer from the file and multiplies the negative numbers together to find their product. It also keeps track of whether there are any negative numbers in the group.

After processing all the numbers, the program checks if there were any negative numbers. If there were, it prints the product of the negative numbers and determines whether the product is negative or not. If there were no negative numbers, it prints a message indicating that.

Please make sure to replace "input.txt" with the actual name of your input file in the program.

I hope this helps! Let me know if you have any further questions.

0 0

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос