18. Bir o’lchamli sonli massivni o’rtacha qiymatidan kichik elementlarini o’rtacha qiymati hisoblansin


Download 280.62 Kb.
Sana04.02.2023
Hajmi280.62 Kb.
#1164225

18.Bir o’lchamli sonli massivni o’rtacha qiymatidan kichik elementlarini o’rtacha qiymati hisoblansin.

#include


using namespace std;
int main()
{
int n;
cout << "Enter the number of elements in the array: ";
cin >> n;
int *arr = new int[n];
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
int sum = 0;
for (int i = 0; i < n; i++)
{
sum += arr[i];
}
double average = sum / n;
int count = 0;
for (int i = 0; i < n; i++)
{
if (arr[i] < average)
{
count++;
}
}
int *arr2 = new int[count];
int j = 0;
for (int i = 0; i < n; i++)
{
if (arr[i] < average)
{
arr2[j] = arr[i];
j++;
}
}
sum = 0;
for (int i = 0; i < count; i++)
{
sum += arr2[i];
}
average = sum / count;
cout << "The average value of numbers smaller than the average value of the array is " << average << endl;
delete[] arr;
delete[] arr2;
return 0;
}


Download 280.62 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling