1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
#include <cstdlib>
#include <iostream>
using namespace std;
void getData(int array[], int size);
void printData(int array[], int size);
int lowestValue(int array[], int size);
int highestValue(int array[], int size);
int countEvens(int array[], int size);
int countOdds(int array[], int size);
int sum(int array[], int size);
int average(array[], int size);
int new_average(array[], int size);
int* getDuplicateValues(int array[], int out[], int size);
int main() {
int array[10], out[10];
getData(array, 10);
printData(array, 10);
int low = lowestValue(array, 10);
int high = highestValue(array, 10);
int odds = countOdds(array, 10);
int evens = countEvens(array, 10);
int sum1 = sum(array, 10);
int average1 = average(array, 10);
int average2 = new_average(array, 10);
int *out1 = getDuplicateValues(array, out, 10);
cout << "Lowest element : " << low << endl;
cout << "Highest element : " << high << endl;
cout << "Odd counts : " << odds << endl;
cout << "Sum of array : " << sum1 << endl;
cout << "Even Average of the array : " << average1 << endl;
cout << "Odd Average of the array : " << average2 << endl;
cout << "Duplicate elements : ";
for (int i = 0; i < 10; i++)
if (*(out + i) != 1)
cout << *(out + i) << " ";
cout << endl;
return 0;
}
void getData(int array[], int size)
{
cout << "Enter 10 integers (separated by a space): : " << endl;
for (int i = 0; i < size; i++)
cin >> array[i];
}
void printData(int array[], int size)
{
for (int i = 0; i < size; i++)
cout << "Array[" << i << "]: " << array[i] << endl;
cout << endl;
}
int lowestValue(int array[], int size)
{
int min = array[0];
for (int i = 1; i < size; i++)
if (array[i] < min)
min = array[i];
return min;
}
int highestValue(int array[], int size)
{
int max = array[0];
for (int i = 1; i < size; i++)
if (array[i] > max)
max = array[i];
return max;
}
int countOdds(int array[], int size)
{
int count = 0;
for (int i = 0; i < size; i++)
if (array[i] % 2 != 0)
count++;
return count;
}
int countEvens(int array[], int size)
{
int count = 0;
for (int i = 0, i < size; i++)
if (array[i] % 2 = 0)
count++
return count;
}
int sum(int array[], int size)
{
int sum = 0;
for (int i = 0; i < size; i++)
sum += array[i];
return sum;
}
int average(int array[], int size)
{
int average = 0;
for (int i = 0; i < size; i++)
sum / evens;
return average;
}
int new_average(int array[], int size)
{
int new_average = 0;
for (int i = 0; i < size; i++)
sum / odds;
return new_average;
}
int* getDuplicateValues(int array[], int out[], int size) {
for (int i = 0; i < size; i++)
out[i] = 1;
for (int i = 0; i < size; i++)
{
int count = 1;
for (int j = i + 1; j < size; j++)
{
if (array[i] == array[j])
count++;
}
if (count > 1)
out[i] = array[i];
}
return out;
}
|