Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: can this be done recursively |
| Date | 2015-04-19 21:14 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87r3rf7u5d.fsf@bsb.me.uk> (permalink) |
| References | <b0319922-1b5e-48d2-8cc7-5cd1a5e866e6@googlegroups.com> |
G G <gdotone@gmail.com> writes: > This problem comes from "C How to Program" by Deitel and Deitel > > 5.18 > > (Even or Odd) Write a program that inputs a series of integers > and passes them one at a time to function even, which uses the remainder > operator to determine whether an integer is even. The function should > take an integer argument and return 1 if the integer is even and 0 > otherwise. > > this is from chapter 5, arrays have not been introduced yet, recursion has. > > no need to show an answer, i'm just curious. Yes, you could write the loop recursively. (You could even write the parity test as a recursive pair of functions though that would be just for fun.) > to solve the problem where it can continuous have input, i used a while loop > and a sentinel. That's almost certainly how the book expects you to do it, though I prefer to avoid sentinels. Simply looping while a number can be read almost always leads to a simpler program. -- Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
can this be done recursively G G <gdotone@gmail.com> - 2015-04-19 09:50 -0700
Re: can this be done recursively Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-04-19 21:14 +0100
Re: can this be done recursively G G <gdotone@gmail.com> - 2015-04-19 14:20 -0700
Re: can this be done recursively Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-04-19 16:32 -0400
Re: can this be done recursively G G <gdotone@gmail.com> - 2015-04-19 14:25 -0700
Re: can this be done recursively Keith Thompson <kst-u@mib.org> - 2015-04-19 14:09 -0700
Re: can this be done recursively G G <gdotone@gmail.com> - 2015-04-19 14:35 -0700
Re: can this be done recursively jt@toerring.de (Jens Thoms Toerring) - 2015-04-19 22:57 +0000
Re: can this be done recursively G G <gdotone@gmail.com> - 2015-04-20 04:30 -0700
Re: can this be done recursively Richard Heathfield <rjh@cpax.org.uk> - 2015-04-20 12:49 +0100
Re: can this be done recursively G G <gdotone@gmail.com> - 2015-04-20 05:28 -0700
Re: can this be done recursively jt@toerring.de (Jens Thoms Toerring) - 2015-04-20 13:09 +0000
Re: can this be done recursively G G <gdotone@gmail.com> - 2015-04-22 09:42 -0700
Re: can this be done recursively Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-04-22 10:12 -0700
Re: can this be done recursively James Kuyper <jameskuyper@verizon.net> - 2015-04-22 13:29 -0400
Re: can this be done recursively Ben Bacarisse <ben.lists@bsb.me.uk> - 2015-04-22 20:57 +0100
Re: can this be done recursively James Kuyper <jameskuyper@verizon.net> - 2015-04-22 16:12 -0400
Re: can this be done recursively Ben Bacarisse <ben.lists@bsb.me.uk> - 2015-04-22 23:14 +0100
Re: can this be done recursively James Kuyper <jameskuyper@verizon.net> - 2015-04-22 18:56 -0400
Re: can this be done recursively G G <gdotone@gmail.com> - 2015-04-23 07:59 -0700
csiph-web