Thread: Program Of Even Or Odd

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    13

    Program Of Even Or Odd

    write a function which ask a user to type a number, it then tells whether the number input is Even Or Odd?

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Ok, easy stuff... what have you got so far... Post your code and lets see what we can do...

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Use the modulo % operator.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    13
    Quote Originally Posted by CommonTater View Post
    Ok, easy stuff... what have you got so far... Post your code and lets see what we can do...
    Code:
    #include<stdio.h>
    #include<conio.h>
    void even(void);
    void main(void)
    {
    clrscr();
    even();
    
    even();
    getche();
    }
    
    void even(void)
    {
    int x;
    printf("\n\nType A Number :");
    scanf("%d",&x);
    if(x%2==0)
    {printf("\n\nYou Typed Even Number");}
    else
    {
    printf("\n\nYou Typed Odd Number");
    }
    }

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by snayyer View Post
    Code:
    #include<stdio.h>
    #include<conio.h>
    void even(void);
    void main(void)
    {
    clrscr();
    even();
    
    even();
    getche();
    }
    
    void even(void)
    {
    int x;
    printf("\n\nType A Number :");
    scanf("%d",&x);
    if(x%2==0)
    {printf("\n\nYou Typed Even Number");}
    else
    {
    printf("\n\nYou Typed Odd Number");
    }
    }
    Hmmm... try it like this....

    Code:
    #include <stdio.h> 
    #include <conio.h>          // warning, not standard C!
    
    int IsOdd(int Num)
      { return Num & 1; }      // odd integers have 1 in bit 0
    
    int main ( void )
     { 
        int uNum = 0;
    
        clrscr();               // warning, not standard C!
    
        printf("Enter a number : ");
        scanf("%d", &uNum);
        if ( IsOdd( uNum ) )
         printf(" %d is an odd number", uNum);
       else
        printf(" %d is an even number", uNum);
    
        return 0;
    }

  6. #6
    Registered User
    Join Date
    Mar 2011
    Posts
    13
    hmmmmmmmmmm

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c program help :>
    By n2134 in forum C Programming
    Replies: 9
    Last Post: 02-06-2010, 12:12 PM
  2. Odd issue with program
    By TigerTank77 in forum C Programming
    Replies: 8
    Last Post: 05-12-2009, 12:00 AM
  3. Help C program that reads Odd numbers and evens
    By Cyberman86 in forum C Programming
    Replies: 4
    Last Post: 02-27-2009, 11:59 AM
  4. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  5. Odd program crashes
    By Mithoric in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2004, 11:37 PM