fork download
  1. program Day
  2. implicit none
  3. integer::d
  4. integer::day_of_year
  5. integer::i
  6. integer::leap_day
  7. integer::month
  8. integer::year
  9. print *,'This program calculates the day of year given the'
  10. print *,'current date.Enter current month(1-12),day(1-31),'
  11. print *,'and year in that order'
  12. read *,month,d,year
  13. if(mod(year,400)==0)then
  14. leap_day=1
  15. else if(mod(year,100)==0)then
  16. leap_day=0
  17. else if(mod(year,4)==0)then
  18. leap_day=1
  19. else
  20. leap_day=0
  21. end if
  22. day_of_year=d
  23. do i=1,month-1
  24. select case(i)
  25. case(1,3,5,7,8,10,12)
  26. day_of_year=day_of_year+31
  27. case(4,6,9,11)
  28. day_of_year=day_of_year+30
  29. case(2)
  30. day_of_year=day_of_year+28+leap_day
  31. end select
  32. end do
  33. print *,'Day=',d
  34. print *,'Month=',month
  35. print *,'Year=',year
  36. print *,'day of year=',day_of_year
  37. end program
Success #stdin #stdout 0.01s 5320KB
stdin
2 28 2023
stdout
 This program calculates the day of year given the
 current date.Enter current month(1-12),day(1-31),
 and year in that order
 Day=          28
 Month=           2
 Year=        2023
 day of year=          59