-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayExample.cpp
More file actions
57 lines (44 loc) · 1.1 KB
/
ArrayExample.cpp
File metadata and controls
57 lines (44 loc) · 1.1 KB
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
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
const int size = 10;
// Arrayi random nomrelerle doldurur
void setRandomNums(int arr[], int size) {
srand(time(NULL));
for (int i = 0; i < size; i++) {
arr[i] = rand() % 100;
}
}
// Arrayin elementlerinin kicikden boyuye siralayir
void sortArray(int arr[], int size) {
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
if (arr[i] > arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
// Array elementlerinin cemini hesablayir
int sumArrayElements(int arr[], int size) {
int sum = 0;
for (int i = 0; i < size; i++) {
sum += arr[i];
}
return sum;
}
int main() {
int arr[size];
setRandomNums(arr, size);
sortArray(arr, size);
int sum = sumArrayElements(arr, size);
cout << endl << "Array : " ;
for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
cout << endl << "Elementleri cemi: " << sum << endl;
return 0;
}