Thread: just a question

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    12

    just a question

    I know this is just a simple problem. I am new cprogramming student and I would like to know what and how I can incorporate the "%" function.

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Make a program that finds all the even or odd numbers below a user-inputted number.

  3. #3
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    "%" is a so called "modulo" or as in school so called "remainder"....

    i.e.

    5 % 2 = 1...........

    when you modulo (divide) 5 by 2... you see that two 2's fits in it making 4 and the remainder is 1......

  4. #4
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    One use is to test for an even number...

    short int number = 5;

    if (!(number % 2))
    {
    cout << "Even number!";
    } else {
    cout << "Odd number!";
    }

  5. #5
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    for single line if (and maybe else) statements, you don't need the "{" and "}". Although, I could be wrong.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    12
    Hey thx for the help that really cleared things up.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM