Using C, Looping using IF to prints numbers 1-10 to say whether odd or even

Discussion in 'C Programming' started by Peanuts, Oct 11, 2006.

  1. Peanuts

    Peanuts

    Joined:
    Oct 11, 2006
    Messages:
    1
    Can you help me construct a programme using C.

    Using looping methods and the IF constrcut to print the numbers between 1 and 10 along with an idications of whether each is even or odd. Like this

    1 is odd
    2 is even
    3 is odd


    Many Thanks

    Peanuts
     
    Peanuts, Oct 11, 2006
    #1
    1. Advertising

  2. Peanuts

    Firestone

    Joined:
    Nov 17, 2006
    Messages:
    2
    I dont know about the computer actually figuring it out, but you can just make it every other like:

    #include <stdio.h>
    int main(void)
    {
    int a;
    a=1;
    while (a<=10)
    {
    printf("\n%d is odd",a);
    a=a+1;
    printf("\n%d is even",a);
    a=a+1;
    }

    printf("\n\n");
    return 0;
    }
    Should do it.
     
    Firestone, Nov 17, 2006
    #2
    1. Advertising

  3. Peanuts

    Rudresh R kaddipudi

    Joined:
    Nov 9, 2006
    Messages:
    4
    Location:
    Bangalore
    Finding whether number is odd or even

    Logic: Odd numbers yields 1 as remainder when it is divided by 2;

    int a=0;
    while(a<=10)
    {
    if(a++%2>0)
    printf("%d is Odd",a);
    else
    printf("%d is Even",a);
    }
     
    Rudresh R kaddipudi, Dec 4, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick

    odd and even signals

    Patrick, Dec 21, 2004, in forum: VHDL
    Replies:
    1
    Views:
    2,829
    Jonathan Bromley
    Dec 21, 2004
  2. Stan Goodman

    Even older fart, even newer newbie

    Stan Goodman, Jul 3, 2003, in forum: Java
    Replies:
    11
    Views:
    722
    Stan Goodman
    Jul 4, 2003
  3. shilpi.rustagi@beesys.com
    Replies:
    2
    Views:
    401
    Phlip
    Aug 2, 2006
  4. giuseppe.amatulli@gmail.com

    looping in array vs looping in a dic

    giuseppe.amatulli@gmail.com, Sep 20, 2012, in forum: Python
    Replies:
    5
    Views:
    304
  5. Zoe Wendy
    Replies:
    2
    Views:
    168
    Steven D'Aprano
    Jun 15, 2013
Loading...

Share This Page