
Хто добре знає С++ Дано масив А(15). Знайти кількість елементів, більших заданого числа
B.приклади програм.Програма1:// Дано масив А(15). Замінити додатні елементи масиву найменшим// елементом.#include <iostream>using namespace std;const int n = 15;int main(){ int i; float min, A[n]; for(i = 0; i < n; i++) { cout << "A[" << i << "]="; cin >> A[i]; } min = A[0]; for(i = 1; i < n; i++)if (A[i] < min) min = A[i]; for(i = 0; i < n; i++)if (A[i] > 0) A[i] = min; for(i = 0; i < n; i++) cout << "A[" << i << "]=" << A[i] << endl; return 0;}Програма2:// Дано масив А(15). Замінити додатні елементи масиву найменшим// елементом.#include <iostream>using namespace std;const int n = 15;int main(){ int i; float min, A[n] = {3.05,-9,-5,22.5,12,-6.045,5,9,3,-5,4.1,8,1,0,15}; min = *A; for(i = 1; i < n; i++)if ( *(A + i) < min) min = *(A + i); for(i = 0; i < n; i++)if ( *(A + i) > 0) *(A + i) = min; for(i = 0; i < n; i++) cout << "A[" << i << "]=" << *(A + i) << endl; return 0;}

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

// Програма1:
#include <iostream>
using namespace std;
const int n = 15;
int main() {
int i, count;
float B, A[n];
cout << "B=";
cin >> B;
for(i = 0; i < n; i++){
cout << "A[" << i << "]="; cin >> A[i];
}
count = 0;
for(i = 0; i < n; i++)
if (A[i] > B)
count++;
cout << count << endl;
return 0;
}
// Програма2:
#include <iostream>
using namespace std;
const int n = 15;
int main() {
int i, count;
float B, A[n] = {3.05,-9,-5,22.5,12,-6.045,5,9,3,-5,4.1,8,1,0,15};
cout << "B=";
cin >> B;
count = 0;
for(i = 0; i < n; i++)
if (*(A + i) > B)
count++;
cout << count << endl;
return 0;
}



To find the number of elements in array A that are greater than a given number B, you can use a loop to iterate through the array and count the elements that meet the condition. Here are two examples of programs that accomplish this task:
Program 1:
```cpp
#include
const int n = 15;
int main() { int A[n]; int B; int count = 0;
cout << "Enter the elements of array A: " << endl; for (int i = 0; i < n; i++) { cout << "A[" << i << "] = "; cin >> A[i]; }
cout << "Enter the value of B: "; cin >> B;
for (int i = 0; i < n; i++) { if (A[i] > B) { count++; } }
cout << "The number of elements in array A that are greater than " << B << " is: " << count << endl;
return 0; } ```
Program 2:
```cpp
#include
const int n = 15;
int main() { float A[n] = {3.05, -9, -5, 22.5, 12, -6.045, 5, 9, 3, -5, 4.1, 8, 1, 0, 15}; float B; int count = 0;
cout << "Enter the value of B: "; cin >> B;
for (int i = 0; i < n; i++) { if (A[i] > B) { count++; } }
cout << "The number of elements in array A that are greater than " << B << " is: " << count << endl;
return 0; } ```
In both programs, the user is prompted to enter the elements of array A. The first program takes input from the user, while the second program initializes the array with predefined values. Then, the user is asked to enter the value of B. The programs then iterate through the array and count the number of elements that are greater than B. Finally, the programs output the count.
Please note that the second program assumes that the array A has already been initialized with values. If you want to modify the program to take input from the user, you can replace the initialization line with the input loop from the first program.
I hope this helps! Let me know if you have any further questions.


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