diff --git a/main.cpp b/main.cpp index 012012f..1a56a90 100644 --- a/main.cpp +++ b/main.cpp @@ -60,7 +60,7 @@ int main() { if (fact != -1) { cout << "[SONUC] " << n << "! = " << fact << endl; } else { - cout << "[HATA] Negatif sayilarin faktoriyeli hesaplanamaz." << endl; + cout << "[HATA] Girdi negatif veya faktoriyel sonucu long long turune sigmiyor." << endl; } break; } @@ -81,4 +81,4 @@ int main() { } while (choice != 0); return 0; -} \ No newline at end of file +} diff --git a/operations.cpp b/operations.cpp index b9bfc0b..d18fa82 100644 --- a/operations.cpp +++ b/operations.cpp @@ -1,5 +1,6 @@ #include "operations.h" #include +#include using namespace std; @@ -10,6 +11,7 @@ long long calculateFactorial(int n) { long long result = 1; for (int i = 2; i <= n; ++i) { + if (result > numeric_limits::max() / i) return -1; result *= i; } return result; @@ -44,4 +46,4 @@ void displayArray(const int* arr, int size) { cout << arr[i] << " "; } cout << "]" << endl; -} \ No newline at end of file +}