fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. // Rakımı hesaplamalarda kullanmak için sabit bir değer olarak belirliyoruz
  5. const double ELEVATION = 850.0; // metre cinsinden
  6.  
  7. // Dereceyi Radyana Çevir
  8. double degToRad(double degree) {
  9. return degree * M_PI / 180.0;
  10. }
  11.  
  12. // Radyanı Dereceye Çevir
  13. double radToDeg(double radian) {
  14. return radian * 180.0 / M_PI;
  15. }
  16.  
  17. // Bir değeri 0 ile 360 arasında tutar
  18. double moreLess360(double value) {
  19. while (value > 360 || value < 0) {
  20. if (value > 360)
  21. value -= 360;
  22. else if (value < 0)
  23. value += 360;
  24. }
  25. return value;
  26. }
  27.  
  28. // Bir değeri 0 ile 24 arasında tutar
  29. double moreLess24(double value) {
  30. while (value > 24 || value < 0) {
  31. if (value > 24)
  32. value -= 24;
  33. else if (value < 0)
  34. value += 24;
  35. }
  36. return value;
  37. }
  38.  
  39. // Ondalık saati Saat ve Dakikaya çevir
  40. void doubleToHrMin(double number, int &hours, int &minutes) {
  41. hours = std::floor(moreLess24(number));
  42. minutes = std::floor(moreLess24(number - hours) * 60);
  43. }
  44.  
  45. // Namaz vakitlerini hesaplar
  46. void calcPrayerTimes(int year, int month, int day,
  47. double longitude, double latitude, int timeZone,
  48. double fajrTwilight, double ishaTwilight,
  49. double &fajrTime, double &sunRiseTime, double &zuhrTime,
  50. double &asrTime, double &maghribTime, double &ishaTime) {
  51. double D = (367 * year) - ((year + static_cast<int>((month + 9) / 12)) * 7 / 4) + ((275 * month / 9) + day - 730531.5);
  52. double L = moreLess360(280.461 + 0.9856474 * D);
  53. double M = moreLess360(357.528 + 0.9856003 * D);
  54. double Lambda = moreLess360(L + 1.915 * std::sin(degToRad(M)) + 0.02 * std::sin(degToRad(2 * M)));
  55. double Obliquity = 23.439 - 0.0000004 * D;
  56. double Alpha = radToDeg(std::atan(std::cos(degToRad(Obliquity)) * std::tan(degToRad(Lambda))));
  57. Alpha = moreLess360(Alpha + 90 * (std::floor(Lambda / 90) - std::floor(Alpha / 90)));
  58. double ST = 100.46 + 0.985647352 * D;
  59. double Dec = radToDeg(std::asin(std::sin(degToRad(Obliquity)) * std::sin(degToRad(Lambda))));
  60. double Durinal_Arc = radToDeg(std::acos((std::sin(degToRad(-0.8333 - 0.0347 * std::sqrt(ELEVATION))) - std::sin(degToRad(Dec)) * std::sin(degToRad(latitude))) /
  61. (std::cos(degToRad(Dec)) * std::cos(degToRad(latitude)))));
  62. double Noon = moreLess360(Alpha - ST);
  63. double UT_Noon = Noon - longitude;
  64.  
  65. ////////////////////////////////////////////
  66. // Namaz Vakitlerinin Hesaplanması
  67. //////////////////////////////////////////
  68.  
  69. // Temkin değerleri
  70. double fajrTemkin = 0.0;
  71. double sunriseTemkin = 0.0;
  72. double zuhrTemkin = 0.0;
  73. double asrTemkin = 0.0;
  74. double maghribTemkin = 0.0;
  75. double ishaTemkin = 0.0;
  76.  
  77. // Öğle vakti [yerel öğle]
  78. zuhrTime = UT_Noon / 15.0 + timeZone + zuhrTemkin;
  79.  
  80. // İkindi vakti
  81. double Asr_Alt = radToDeg(std::atan(1 + std::tan(degToRad(std::fabs(latitude - Dec)))));
  82. double Asr_Arc = radToDeg(std::acos((std::sin(degToRad(90 - Asr_Alt)) - std::sin(degToRad(Dec)) * std::sin(degToRad(latitude))) /
  83. (std::cos(degToRad(Dec)) * std::cos(degToRad(latitude))))) / 15.0;
  84. asrTime = zuhrTime + Asr_Arc + asrTemkin;
  85.  
  86. // Sabah vakti
  87. sunRiseTime = zuhrTime - Durinal_Arc / 15.0 + sunriseTemkin;
  88.  
  89. // Akşam vakti
  90. maghribTime = zuhrTime + Durinal_Arc / 15.0 + maghribTemkin;
  91.  
  92. double Esha_Arc = radToDeg(std::acos((std::sin(degToRad(ishaTwilight)) - std::sin(degToRad(Dec)) * std::sin(degToRad(latitude))) /
  93. (std::cos(degToRad(Dec)) * std::cos(degToRad(latitude))))) / 15.0;
  94. ishaTime = zuhrTime + Esha_Arc + ishaTemkin;
  95.  
  96. double Fajr_Arc = radToDeg(std::acos((std::sin(degToRad(fajrTwilight)) - std::sin(degToRad(Dec)) * std::sin(degToRad(latitude))) /
  97. (std::cos(degToRad(Dec)) * std::cos(degToRad(latitude))))) / 15.0;
  98. fajrTime = zuhrTime - Fajr_Arc + fajrTemkin;
  99. }
  100.  
  101. int main() {
  102. double fajr, sunRise, zuhr, asr, maghrib, isha;
  103. calcPrayerTimes(2024, 11, 12, 32.8497, 39.9114, 3, -19, -17, fajr, sunRise, zuhr, asr, maghrib, isha);
  104.  
  105. int hours, minutes;
  106.  
  107. doubleToHrMin(fajr, hours, minutes);
  108. std::cout << "Fajr: " << hours << ":" << minutes << std::endl;
  109.  
  110. doubleToHrMin(sunRise, hours, minutes);
  111. std::cout << "Sunrise: " << hours << ":" << (minutes < 10 ? "0" : "") << minutes << std::endl;
  112.  
  113. doubleToHrMin(zuhr, hours, minutes);
  114. std::cout << "Zuhr: " << hours << ":" << (minutes < 10 ? "0" : "") << minutes << std::endl;
  115.  
  116. doubleToHrMin(asr, hours, minutes);
  117. std::cout << "Asr: " << hours << ":" << (minutes < 10 ? "0" : "") << minutes << std::endl;
  118.  
  119. doubleToHrMin(maghrib, hours, minutes);
  120. std::cout << "Maghrib: " << hours << ":" << (minutes < 10 ? "0" : "") << minutes << std::endl;
  121.  
  122. doubleToHrMin(isha, hours, minutes);
  123. std::cout << "Isha: " << hours << ":" << (minutes < 10 ? "0" : "") << minutes << std::endl;
  124.  
  125. return 0;
  126. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Fajr: 5:51
Sunrise: 7:24
Zuhr: 12:32
Asr: 15:13
Maghrib: 17:40
Isha: 19:03