Thread: Even or Odd (practice problem)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    8

    Even or Odd (practice problem)

    This is not homework but it is supposed to be the third warm up before I actually begin the homework. I asked my lab instructor but he said to declare the function but i do not know what he is talking about. It stops when it hits the
    Code:
     return ( even( n - 1 ));	/*     n is odd if and only n-1 is even
    I have deleted it, but when i do that the comp says everything is odd

    Code:
     #include <stdio.h>
    
    
    int odd(int n)
    {
       if ( n == 1 )	/*     if n is 1 then it is certainly true that it is odd      */
          return ( 1 );
       else
          return ( even( n - 1 ));	/*     n is odd if and only n-1 is even                */
    }
    
    int even(int n)
    {
       if ( n == 0 )	/*     if n is 0 then it is certainly true that it is even    */
          return ( 1 );
       else
          return ( odd( n - 1) );	/*     n is even if and only n-1 is odd                */
    }
    
    main()
    {
       int N;
    
       printf("Please input a n integer.\n");
       scanf("%d", &N);
    
       if ( odd(N) )
            printf("The number %d is odd.\n", N);
       else
            printf("The number %d is even.\n", N);
    }
    Last edited by Amphibian; 09-13-2010 at 03:37 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  2. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  3. Words and lines count problem
    By emo in forum C Programming
    Replies: 1
    Last Post: 07-12-2005, 03:36 PM
  4. inStream practice problem not working?
    By correlcj in forum C++ Programming
    Replies: 2
    Last Post: 10-27-2002, 05:58 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM