Remainder Operator? menu

Shout-Out

User Tag List

Results 1 to 4 of 4
  1. #1
    Applellial's Avatar Corporal
    Reputation
    1
    Join Date
    Feb 2011
    Posts
    23
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Remainder Operator?

    What is a remiander operator? Can u please give me any example of program it is used in? Write an application that read two integers, determines whether first is a multiple of second and prints the result.

    Remainder Operator?
  2. #2
    DarkLinux's Avatar Former Staff
    CoreCoins Purchaser Authenticator enabled
    Reputation
    1627
    Join Date
    May 2010
    Posts
    1,846
    Thanks G/R
    193/539
    Trade Feedback
    16 (100%)
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    A computer cant really do math like multiplication, division even subtraction. All a computer can do is add. It can do multiplication, division and subtraction by add and bit shifting or remainder.

    Anyways what u are looking for is this,
    int Remiander = 10 % 2
    Remiander = 0
    Therefor 2 is a multiple of 10...

    So if u divide the 1st number by the 2nd number and u dont get a remainder, then the number divisible. Therefor I think it must be a multiple ...
    Last edited by DarkLinux; 06-10-2011 at 10:58 PM.

  3. #3
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by DarkLinux View Post
    A computer cant really do math, it cant do multiplication, division even subtraction. All a computer can do is add. It can do multiplication, division and subtraction by add and bit shifting or remainder.

    Anyways what u are looking for is this,
    int Remiander = 10 % 2
    Remiander = 0
    Therefor 2 is a multiple of 10...

    So if u divide the 1st number by the 2nd number and u dont get a remainder, then the number divisible. Therefor I think it must be a multiple ...
    A computer can't really do math? Well gee, I guess the ALU in my processor must just be idling and wasting resources. I'm gonna go disable it now. Afk.

  4. #4
    bonehand's Avatar Member
    Reputation
    2
    Join Date
    Aug 2009
    Posts
    61
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To say they just add is a bit off...adding a negative of a number IS subtraction. And the process of shifting a bit right or left IS multiplication and division. Just because a CPU converts everything to binary doesn't mean that it's no longer mathematics. Even the most basic ALU makes the mathematics even more like what you are describing as 'math'...since it allows logical 'shortcuts' that speed mathematics using cpu architecure using some of the same rules that we use to do the calculations. ie 1 AND 0 = 0 is equivalent to 1*0=0 or 7*0=0 is equivalent to (1011 AND 0000) = 0000...using bitwise operations, and one's and two's complements at the most basic level make these calculations easier for a computer. More advanced ALU's (those made since the 80's) actually can do multiplication and division in every way...it's still with 1 or 0 bits, but just because a Frenchman uses french numbers to calculate Pi doesn't mean he's not doing math by US standards...

    Anyway:

    1%1=0
    2%1=0
    3%1=0
    ...
    2%2=0
    3%2=1
    4%2=0
    5%2=1
    ...
    3%3=0
    4%3=1
    5%3=2
    6%3=0
    ...

    It's not called the remainder function, btw, it is the modulo or mod function...see Modulo operation - Wikipedia, the free encyclopedia for more

    Code:
    #!/usr/bin/env perl
    # Perl ftw!
    $a = shift;
    $b = shift;
    
    if ($a>$b)
    {
      if ($a%$b==0)
      {
        printf("%d is a multiple of %d\n",$a,$b);
      }
      else
      {
        printf("%d is NOT a multiple of %d",$a,$b);
      }
    }
    else
    {
      if ($b%$a==0)
      {
        printf("%d is a multiple of %d\n",$b,$a);
      }
      else
      {
        printf("%d is NOT a multiple of %d",$b,$a);
      }
    }
    
    exit(0);
    Anyway, that could be done better swapping them out, but this should show you that you would want the larger number before the % and the smaller after....after all, something is never going to be described as a multiple of something larger than itself...

Similar Threads

  1. Replies: 3
    Last Post: 10-22-2008, 06:37 PM
  2. Operating systems?
    By Emuchild in forum Community Chat
    Replies: 2
    Last Post: 05-08-2008, 11:28 PM
  3. Perl operators
    By tttommeke in forum Programming
    Replies: 1
    Last Post: 03-09-2008, 10:44 PM
  4. Operator and me convo, wierd!
    By foxlin in forum World of Warcraft General
    Replies: 3
    Last Post: 02-13-2008, 07:00 PM
  5. How To: Operate GUI's & .exe's
    By Glynbeard in forum Community Chat
    Replies: 7
    Last Post: 10-30-2007, 08:17 AM
All times are GMT -5. The time now is 01:42 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search