Even Odd in Fortran

Published on 29 October 2020 (Updated: 15 October 2025)

Welcome to the Even Odd in Fortran page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

program evenodd
   implicit none
   character(len=12) :: arg
   character(len=52) :: letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
   integer :: number, ios, argc

   argc = command_argument_count()
   if (argc /= 1) call usage()

   call get_command_argument(1, arg)
   if (len_trim(arg) == 0) call usage()
   if (scan(arg, letters) > 0) call usage()

   read(arg, *, iostat=ios) number
   if (ios /= 0) call usage()

   if (mod(number,2) == 0) then
      write(*,*) "Even"
   else
      write(*,*) "Odd"
   end if

contains

   subroutine usage()
      write(*,*) "Usage: please input a number"
      stop
   end subroutine

end program evenodd

Even Odd in Fortran was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.