Selasa, 05 April 2011

Even-odd program with pascal

Even-odd program with pascal
{program to determine whether a number is even or odd}

Declaration:
x: integer

function
even (input n = integer) boolean
(true if n is even number, or false if otherwise)

Algorithm:
read (x)
      if even (x) then
           write ('even')
      else
           write ('odd')
endif


Program

(* declaration *)
var
      x: integer


function even (n : integer) :boolean;
(true if n is even number, or false if otherwise)

begin
     even :=(n mod 2 =0)
end


(*Algorithm*)
begin 
      write('enter any integer  :  '); readln(x);
      if even (x)then
            writeln('even')
      else
             writeln('odd')
     (endif)
end


 

Tidak ada komentar:

Posting Komentar