Velocity Reviews > % question

% question

bart.c
Guest
Posts: n/a

 05-30-2010
pemo wrote:

> PLEASE, 22 / 5 is 4.4 --- right????
>
> So, if % gives the *remainder*, after the whole division; why is it -
> the remainder = '2' rather than '4'!

The remainder is 2 (fifths), or 2/5 as a fraction, or 0.4 in decimal.

The % operator gives the first value.

--
Bartc

Keith Thompson
Guest
Posts: n/a

 05-30-2010
pemo <(E-Mail Removed)> writes:
> On May 30, 7:43Â*pm, Keith Thompson <(E-Mail Removed)> wrote:
>> pemo <(E-Mail Removed)> writes:
>> > On May 30, 5:53Â*pm, Willem <(E-Mail Removed)> wrote:
>> >> pemo wrote:
>> >> ) I'm sure it's obvious, but Â*why is 2 the result of 22 % 5, rather than
>> >> ) 4?

>>
>> >> If you divide 22 by 5, the remainder is 2.

>>
>> >> Why would you expect the result to be 4 ?

>>
>> > Well, Windows calc, given 22 / 5 says the result is 4.4

>>
>> Windows calc is showing you the result of a real division, not an
>> integer division. Â*In C terms, it's computing 22.0 / 5.0, not 22 / 5.
>>
>> If I understand you correctly, you're assuming that the result of
>> "/" should be the 4 that appears before the decimal point (which
>> is correct), and the result of "%" should be the 4 that appears
>> after the decimal point (which is wrong).

[snip]
>
> THANK YOU Keith Thompson - at last, a plain speaking, descriptive and
> down to earth rationale! MANY, many thanks!

You're welcome.

I should point out that I think the reason most people here didn't
understand your problem is that you chose a poor example, and didn't
as a result clearly explain what your misconception was. Don't be
too hard on the people who didn't understand what you were asking.
(I was mostly lucky myself.)

Your example was 22 / 5 = 4.4. You told us (several times) that you
thought 22 / 5 should be 4. Most of us thought you were referring
to the 4 *before* the decimal point; the 4 after the decimal point
is so obviously (to most of us) a fraction that it's hard to think
of it as an integer.

If you had tried 23 / 5 = 4.6 and told us that you thought 23 % 5
should be 6, you might have gotten an explanation sooner. Or if
you had tried 22 / 7 = 3.142857 (approximately), you might have
seen the flaw in your own reasoning, if not the solution.

I'm not suggesting that you should have thought of this yourself;
that probably would have required that you understand the situation,
and then you wouldn't have needed to ask in the first place. But if
you had shown us, say, 2 or 3 different examples and/or tried to
explain more clearly *why* you thought the result should be 4,
that would have helped us to understand your question.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

pemo
Guest
Posts: n/a

 05-30-2010
On May 30, 7:51*pm, James Lothian
<(E-Mail Removed)> wrote:
> pemo wrote:
> > I'm quite happy(ish!) to reveal my ignorance, but as a trusted
> > calculator says that 22/5 is 4.4, why isn't 22 mod 5 == 4 --- surely,
> > 4 *is* the remainder?

>
> > I mean, try it yourself - I have, on a variety of calculators; in my
> > head; on paper etc --- 22/5 IS 4.4, so why isn't 22 mod 5 == 4???

>
> > Please, rather than suggest I read someone else's explanation, please
> > point out why, something that seems so simple is so weird!

>
> I'm speechless.http://en.wikipedia.org/wiki/Remainder.
>
> James

>>> I'm speechless

As I was to your 'contribution' [and your arrogance] - such a valid
contribution (to your ego)!

You know, one can always 'link' to this/that, or 'exclaim' with an 'oh
dear' - things are only obvious to some - the rest of us would like to
learn, sans smarmie know-it-all comments like yours!

c.f. your 'oh dear' with Keith's contribution - then 'relect' for a
moment!

Denis McMahon
Guest
Posts: n/a

 05-30-2010
On 30/05/10 17:26, pemo wrote:
> I'm sure it's obvious, but why is 2 the result of 22 % 5, rather than
> 4?

22 % 5 = 4 remainder 2, the % operator gives the remainder of the
integer division.

22 / 5 as ints will give the 4 that you expect.

/******* code below *******/

#include <stdio.h>

void main(int argc, char * argv[]) {

printf("22 / 5 = %d remainder %d\n",22/5,22%5);

}

/******* code above *******/

Rgds

Denis McMahon

Keith Thompson
Guest
Posts: n/a

 05-30-2010
pemo <(E-Mail Removed)> writes:
> On May 30, 7:51Â*pm, James Lothian
> <(E-Mail Removed)> wrote:
>> pemo wrote:
>> > I'm quite happy(ish!) to reveal my ignorance, but as a trusted
>> > calculator says that 22/5 is 4.4, why isn't 22 mod 5 == 4 --- surely,
>> > 4 *is* the remainder?

>>
>> > I mean, try it yourself - I have, on a variety of calculators; in my
>> > head; on paper etc --- 22/5 IS 4.4, so why isn't 22 mod 5 == 4???

>>
>> > Please, rather than suggest I read someone else's explanation, please
>> > point out why, something that seems so simple is so weird!

>>
>> I'm speechless.http://en.wikipedia.org/wiki/Remainder.
>>
>> James

>
>>>> I'm speechless

>
> As I was to your 'contribution' [and your arrogance] - such a valid
> contribution (to your ego)!
>
> You know, one can always 'link' to this/that, or 'exclaim' with an 'oh
> dear' - things are only obvious to some - the rest of us would like to
> learn, sans smarmie know-it-all comments like yours!
>
> c.f. your 'oh dear' with Keith's contribution - then 'relect' for a
> moment!

If you're going to be participating here, I suggest you grow
a thicker skin. Given the information you gave us, it really
wasn't easy to figure out just what your misunderstanding was.
I think that's why some people reacted as if you has asked why
2 + 2 isn't 22.

In any case, the article at <http://en.wikipedia.org/wiki/Remainder>
would have answered your question. If you're going to insult people
who try to help you, you're not going to get much help.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

spinoza1111
Guest
Posts: n/a

 05-31-2010
On May 31, 2:19*am, pemo <(E-Mail Removed)> wrote:
> On May 30, 7:00*pm, Nick Keighley <(E-Mail Removed)>
> wrote:
>
>
>
>
>
> > On 30 May, 18:42, pemo <(E-Mail Removed)> wrote:

>
> > > On May 30, 5:53*pm, Willem <(E-Mail Removed)> wrote:
> > > > pemo wrote:
> > > > ) I'm sure it's obvious, but *why is 2 the result of 22 % 5, rather than
> > > > ) 4?

>
> > 22 divided by 5 is 4 remainder 2

>
> > % is the remainder operator

>
> > > > If you divide 22 by 5, the remainder is 2.

>
> > > > Why would you expect the result to be 4 ?

>
> > > Well, Windows calc, given 22 / 5 says the result is 4.4

>
> > well / is division not remainder. Also

>
> > 22 / 5 = 4

>
> > because C's / operator applied to integers yeilds an integral answer.
> > Microsoft calc (Calculator?) is dealing with floating variables
> > ("real" numbers) rather than integers.

>
> > You might want to look up floating point to learn more about the
> > representation of numbers in computers.

>
> I'm quite happy(ish!) to reveal my ignorance, but as a trusted
> calculator says that 22/5 is 4.4, why isn't 22 mod 5 == 4 --- surely,
> 4 *is* the remainder?
>
> I mean, try it yourself - I have, on a variety of calculators; in my
> head; on paper etc --- 22/5 IS 4.4, so why isn't 22 mod 5 == 4???
>
> Please, rather than suggest I read someone else's explanation, please
> point out why, something that seems so simple is so weird!

"Do not worry about your problems with mathematics, I assure you mine
are far greater" - Einstein

Keith has explained this very well. Terminology:

integer: a counting number: 0, 1, 2 and so forth: also -1, -2 and so
forth

real number: a measuring number: 0, .25, -.001 and so on

complex number: a multiple of the "nonexistent" square root of -1
times a real number: not used in everyday arithmetic, used in modern
physics. All integers are reals, all reals are complex, and all
equations have a solution if there are complex numbers

dividend: the number being divided

divisor: the number the dividend is being divided by

remainder: the difference between the integer result and the real
result

Lancelot Hogben, "Mathematics for the Million".

Many adults and more teens have in fact not been able to learn
mathematics. Nonetheless, they need to use and even program computers
on the job.

One model of education is that they must learn one thing at a time as
in traditional schools. However, this model often fails to work.

While learning C, it might be an excellent idea to learn basic
mathematics. This integrated approach works, and is recommended by
educator (and political radical) Bill Ayers (cf his book To Teach: the
Journey of a Teacher, Teachers College Press, 2000). Ayers teaches
"basic skills" in K-12 in the context of useful projects such as
mapping one's neighborhood, saving money or doing a survey.

Brazilian educator Paulo Freire also points out that in adult
education, the teacher must respect, use and learn from adult students
who have been deprived of the so-called basics in a conversation. In
this ng, there are a lot of posters who have been in fact mistreated
by traditional educational models: diagnosed and labeled as "not good
at math" or "dyslexic". They've tracked themselves or been tracked in
programming to discover that they are good with computers because
computers "make it real", whereas in traditional classrooms, the
teacher (who's usually herself strikingly ignorant about math) tells
the "slow" children they are "stupid".

I learned finite mathematics by using a computer.

OP, don't be discouraged by some of the replies. Stand up for your
rights. There are a lot of people here with one or more deficiencies
in basic skills including reading comprehension and writing complex
sentences. One of the leading regulars boasts about learning
difficulties while attacking others for theirs.

Keith Thompson, who has answered your question well, tells you to suck
up the sort of abuse that goes on here. I say, don't.

Charlton Wilbur
Guest
Posts: n/a

 05-31-2010
>>>>> "p" == pemo <(E-Mail Removed)> writes:

p> What I'm getting from this is that I'm sure toooo dumb to ask
p> what to most of you is, um, a 'stupid dumb ****' question!

p> PLEASE, 22 / 5 is 4.4 --- right????

Only if you're working with real or rational numbers. If you're working
with integer math, the value 4.4 is impossible, so 22/5 is 4.

p> So, if % gives the *remainder*, after the whole division; why is
p> it - the remainder = '2' rather than '4'!

Because the remainder is not the decimal portion of the quotient.

Go get yourself 22 things. When I was in second grade we used dried
beans, but anything you have 22 of will be handy. Divide them into five
even groups, and note that you can't split them into partial beans.
What happens?

Well, you find that you have 4 groups of 5, and 2 beans left over.

So, when you work with C integers, 22 / 5 is 4. (*NOT* 4.4, because 4.4
is not an integer.) And 22 % 5 is 2, because that's the *remainder*.

Charlton

--
Charlton Wilbur
(E-Mail Removed)

Charles Richmond
Guest
Posts: n/a

 06-01-2010
pemo wrote:
> On May 30, 7:00 pm, Nick Keighley <(E-Mail Removed)>
> wrote:
>> On 30 May, 18:42, pemo <(E-Mail Removed)> wrote:
>>
>>> On May 30, 5:53 pm, Willem <(E-Mail Removed)> wrote:
>>>> pemo wrote:
>>>> ) I'm sure it's obvious, but why is 2 the result of 22 % 5, rather than
>>>> ) 4?

>> 22 divided by 5 is 4 remainder 2
>>
>> % is the remainder operator
>>
>>>> If you divide 22 by 5, the remainder is 2.
>>>> Why would you expect the result to be 4 ?
>>> Well, Windows calc, given 22 / 5 says the result is 4.4

>> well / is division not remainder. Also
>>
>> 22 / 5 = 4
>>
>> because C's / operator applied to integers yeilds an integral answer.
>> Microsoft calc (Calculator?) is dealing with floating variables
>> ("real" numbers) rather than integers.
>>
>> You might want to look up floating point to learn more about the
>> representation of numbers in computers.

>
> I'm quite happy(ish!) to reveal my ignorance, but as a trusted
> calculator says that 22/5 is 4.4, why isn't 22 mod 5 == 4 --- surely,
> 4 *is* the remainder?
>
> I mean, try it yourself - I have, on a variety of calculators; in my
> head; on paper etc --- 22/5 IS 4.4, so why isn't 22 mod 5 == 4???
>
> Please, rather than suggest I read someone else's explanation, please
> point out why, something that seems so simple is so weird!
>
>

The 0.4 is *not* the remainder. 5 * 0.4 = 2. Two is the remainder.

--
+----------------------------------------+
| Charles and Francis Richmond |
| |
| plano dot net at aquaporin4 dot com |
+----------------------------------------+

Nick Keighley
Guest
Posts: n/a

 06-01-2010
On 30 May, 19:19, pemo <(E-Mail Removed)> wrote:
> On May 30, 7:00*pm, Nick Keighley <(E-Mail Removed)>
> > On 30 May, 18:42, pemo <(E-Mail Removed)> wrote:
> > > On May 30, 5:53*pm, Willem <(E-Mail Removed)> wrote:
> > > > pemo wrote:

> > > > ) I'm sure it's obvious, but *why is 2 the result of 22 % 5, rather than
> > > > ) 4?

>
> > 22 divided by 5 is 4 remainder 2

>
> > % is the remainder operator

I was taught division in a day before calculators. On being first
taught division we were taught it as an operation on integers (no
fractions or decimals). Division was repeated subtraction and
subtraction was a big word meaning "to take away". You have 22 apples
to divide as best you can between 5 people.

22 take away 5 = 17 each person has 1 apple
17 take away 5 = 13 each person has 2 apples
12 take away 5 = 7 each person has 3 apples
7 take away 5 = 2 each person has 4 apples

So each person gets 4 apples and there 2 left over. That was they
called "the remainder" because it was what remained after you had done
as many take-aways as possible. Made sense to me when I was 6.

The remainder operator % is still sometimes useful.

> > > > If you divide 22 by 5, the remainder is 2.

>
> > > > Why would you expect the result to be 4 ?

>
> > > Well, Windows calc, given 22 / 5 says the result is 4.4

>
> > well / is division not remainder. Also

>
> > 22 / 5 = 4

>
> > because C's / operator applied to integers yeilds an integral answer.
> > Microsoft calc (Calculator?) is dealing with floating variables
> > ("real" numbers) rather than integers.

>
> > You might want to look up floating point to learn more about the
> > representation of numbers in computers.

really, you should do this

> I'm quite happy(ish!) to reveal my ignorance,

I've never seen in problem with admitting to ignorance. How else are
you going to learn things?

> but as a trusted
> calculator says that 22/5 is 4.4, why isn't 22 mod 5 == 4 --- surely,
> 4 *is* the remainder?
>
> I mean, try it yourself - I have, on a variety of calculators; in my
> head; on paper etc --- 22/5 IS 4.4, so why isn't 22 mod 5 == 4???

because you have a misapprehension as to the meaning of mod

> Please, rather than suggest I read someone else's explanation, please
> point out why, something that seems so simple is so weird!

please assume I have a reason for suggesting you learn the basics. It
took quite some time for other posters to disentangle what your
misapprehension was. Being a toutorial for infant school mathematics
seems a bit much for a newsgroup devoted to a programming language.

You might think of getting a better attitude if you want answers to
future questions.

Happy Programming.