-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperations.cpp
More file actions
47 lines (39 loc) · 1.02 KB
/
Copy pathoperations.cpp
File metadata and controls
47 lines (39 loc) · 1.02 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
#include "operations.h"
#include <iostream>
using namespace std;
// Faktöriyel hesaplama (Iteratif yöntem bellek dostudur)
long long calculateFactorial(int n) {
if (n < 0) return -1;
if (n == 0 || n == 1) return 1;
long long result = 1;
for (int i = 2; i <= n; ++i) {
result *= i;
}
return result;
}
// Pointer kullanarak diziyi bellek üzerinde ters çevirme
void reverseArray(int* arr, int size) {
if (arr == nullptr || size <= 1) return;
int start = 0;
int end = size - 1;
while (start < end) {
// Swap islemi
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}
// Diziyi ekrana formatlı yazdırma
void displayArray(const int* arr, int size) {
if (arr == nullptr || size <= 0) {
cout << "[HATA] Dizi bos veya gecersiz." << endl;
return;
}
cout << "[ ";
for (int i = 0; i < size; ++i) {
cout << arr[i] << " ";
}
cout << "]" << endl;
}