i have 2 question that i need help to solve

1. write an algorithm that writes the binary form of a decimal number n

2. if d divides both n and m the d divides their sum and d divides their difference

Results 1 to 3 of 3

- December 14th 2007, 03:22 AM #1monkyshinesGuest

- December 14th 2007, 05:40 AM #2

- Joined
- May 2006
- From
- Lexington, MA (USA)
- Posts
- 11,719
- Thanks
- 634

- December 14th 2007, 06:11 AM #3

- Joined
- May 2006
- From
- Lexington, MA (USA)
- Posts
- 11,719
- Thanks
- 634

Hello, monkyshines!

1. Write an algorithm that writes the binary form of a decimal number

There is a procedure for this, based on the Euclidean Algorithm.

Example: Convert 87 to binary.

[1] Divide by 2, note the remainder.

. . .

[2] Divide the*quotient*by 2, note the remainder.

. . .

[3] Repeat step [2] until a zero quotient is reached.

. . .

[4] Now read**up**the remainders.

Therefore: .

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

A silly but true story . . .

Years ago, I gave this exact problem on an exam.

One of my top students (with a quirky sense of humor) wrote

. . "Hi-yo, Silver!" next to his (correct) answer.

Of course, when I handed the papers back, I asked him about it.

He said, "Did you*read*the number?"

Puzzled, I mentally thought: "One-zero-one-zero-one-one-one."

OMG ... It's the opening of*The William Tell Overture !*

(I said he was quirky, didn't I?)