tobold.org

correct • elegant • free

△ Comp.lang.c △

◅ Source code for a recursive function - Tower of Hanoi

HELP! Are dynamically allocated static arrays possible? ▻

How can I determine if a number is even?

In article <larry_kearney-2510951302140001@kearneymac.appsig.com>,
Lawrence Kearney <larry_kearney@appsig.com> wrote:
>Try the following:

I prefer the recursive solution.

        int isOdd(int);

        int isEven(int n) {
                if (n == 0)
                        return 1;
                else
                        return isOdd(n - 1);
        }

        int isOdd(int n) {
                if (n == 0)
                        return 0;
                else
                        return isEven(n - 1);
        }

Tim.
--
Tim Goodwin   | "... which works fine, but from a language design aesthetics
Unipalm PIPEX | point of view (i.e., mine), is grotesque." -- Chris Torek

Original headers:

From: tim@pipex.net (Tim Goodwin)
Newsgroups: comp.lang.c
Subject: Re: How can I determine if a number is even?
Date: 26 Oct 1995 17:28:19 GMT
Organization: Unipalm PIPEX
Message-ID: <46ogfj$n7v@wave.news.pipex.net>
References: <114303Z25101995@anon.penet.fi>
  <larry_kearney-2510951302140001@kearneymac.appsig.com>

△ Comp.lang.c △

◅ Source code for a recursive function - Tower of Hanoi

HELP! Are dynamically allocated static arrays possible? ▻