% operator

Discussion in 'C' started by vinayak saxena, Oct 10, 2010.

  1. vinayak saxena

    vinayak saxena New Member

    Joined:
    Oct 10, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    what is uses of operator % and what is work please tell me
     
  2. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    19
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    http://www.techgeek.in
    % operator is used for modulus.. i.e. it takes out a remainder...e.g 2%3 gives you 2 and 4%2 gives you 0.
     
  3. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    9
    Trophy Points:
    0
    Use of % operator is mainly to see if the number is divisible by the second number or not.
     
  4. vinayak saxena

    vinayak saxena New Member

    Joined:
    Oct 10, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    2%3 gives you 2 and 4%2 gives you 0. why work that i dont know please tell me the working of modulus % operator:confused:
     
  5. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    9
    Trophy Points:
    0
    Just do 2 mod 3 using pen and paper and you will see that you get 2 as a remainder.
     
  6. aftabsharif

    aftabsharif New Member

    Joined:
    Oct 15, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Bahawalpur
    Hi,
    The '%' sign in c++ called the remainder.Which means that the remainder of some thing as when we devide 5 by 2 then 2 goes only 2 times as 2*2=4 which is less then 5 so the remaining thing is 1.this one is called remainder of 5 by two.it can be written as
    5%2=1.
    I hope this enough for you to understand the working of '%' in c++.If it not works then tell me again.
     
  7. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    19
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    http://www.techgeek.in
    Was there any subject in your school known as "Mathematics"? In mathematics there is a concept known as "remainder"...read that first and then ask question....
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice