# Dividing numbers into Zero

Page 1 of 1

## 14 Replies - 1305 Views - Last Post: 05 September 2009 - 01:00 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=123895&amp;s=bc7618a3534eedf84e73232d43f55a69&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 leizyl

Reputation: 0
• Posts: 2
• Joined: 04-September 09

# Dividing numbers into Zero

Posted 04 September 2009 - 04:05 AM

somebody helps me to make a program to divide numbers into zero?
and please show the possible output!!
thanks!!
Is This A Good Question/Topic? 0

## Replies To: Dividing numbers into Zero

### #2 AntonWebsters

• D.I.C Regular

Reputation: 89
• Posts: 428
• Joined: 15-August 09

## Re: Dividing numbers into Zero

Posted 04 September 2009 - 04:42 AM

Quote

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Thank you for helping us helping you.

Here's an idea though. Prompt the user to input a number. By dividing the number by any bigger numbers, you'll get an output of zero. Is that what you want?

This post has been edited by AntonWebsters: 04 September 2009 - 04:43 AM

### #3 syfran

• D.I.C Lover

Reputation: 83
• Posts: 1,103
• Joined: 12-July 09

## Re: Dividing numbers into Zero

Posted 04 September 2009 - 04:45 AM

I know I'm not supposed to give away code but this was a challenge I couldn't pass up.

```int devIntoZero(double toDiv) {
return 0;
}

```

Edit: Got method name completely wrong. I'm a failure.

This post has been edited by syfran: 04 September 2009 - 05:36 AM

### #4 moopet

• binary decision maker

Reputation: 343
• Posts: 1,189
• Joined: 02-April 09

## Re: Dividing numbers into Zero

Posted 04 September 2009 - 05:08 AM

syfran, on 4 Sep, 2009 - 10:45 AM, said:

I know I'm not supposed to give away code but this was a challenge I couldn't pass up.

```int devByZero(double toDiv) {
return 0;
}

```

```
int devIntoZero(double myNutsAreHuge)
{
return 0;
}

```

will give a far more accurate result

### #5 poncho4all

Reputation: 123
• Posts: 1,422
• Joined: 15-July 09

## Re: Dividing numbers into Zero

Posted 04 September 2009 - 05:31 AM

syfran, on 4 Sep, 2009 - 03:45 AM, said:

I know I'm not supposed to give away code but this was a challenge I couldn't pass up.

```int devByZero(double toDiv) {
return 0;
}

```

lol!

What is it that you want exactly. Any number divided by cero is cero.
There is another posible outcome but is not measurable wich could be infinite f3
I think you need to think about what you need.

### #6 Nizbel99

Reputation: 6
• Posts: 117
• Joined: 19-May 09

## Re: Dividing numbers into Zero

Posted 04 September 2009 - 06:01 AM

I'm not quite sure I understand what you want, but from what I can see, there are two things you are possibly asking:
One is, you want to divide 0 by some number (IE: 0 / X), and in this case, the result will ALWAYS be zero, unless X is
also 0. On the other hand, you could be asking to divide a number by zero (IE: X / 0), then you get an undifined
result or infinity. Either way, what your trying to do will always return a constant result; either 0 or infinity/undifined.

Thanks,

Zach

### #7 syfran

• D.I.C Lover

Reputation: 83
• Posts: 1,103
• Joined: 12-July 09

## Re: Dividing numbers into Zero

Posted 04 September 2009 - 06:08 AM

Quote

unless X is
also 0.

Omg, need to revise my code... this shouldn't be that hard...
```int divIntoZero(int toDiv) {
return 1 ^ toDiv; // that works right?
}

```

This post has been edited by syfran: 04 September 2009 - 06:12 AM

### #8 jjl

• Engineer

Reputation: 1270
• Posts: 4,998
• Joined: 09-June 09

## Re: Dividing numbers into Zero

Posted 04 September 2009 - 08:20 AM

you cant divide by zero anyways

### #9 wildgoose

• D.I.C Regular

Reputation: 67
• Posts: 468
• Joined: 29-June 09

## Re: Dividing numbers into Zero

Posted 04 September 2009 - 10:57 AM

Dividing by zero is undefined unless you're working with limits such as in Calculus. As x approaches zero....

There is usually a reason you are dividing in the first place! Typically you are multiplying by the reciprocal of some solution. Such a You are taking the average of N items. But if there weren't any items because the list was empty then you're pre-handled response is my average is zero!

If you are normalizing a number by multiplying their products by their magnitude for each item or component then that can be easily pre-handled too!
```Mag = sqrt( XX+YY+ZZ+WW )
nX = X / Mag
nY = Y / Mag
nZ = Z / Mag
nW = W / Mag

```

But if the magnitude (result of pythagorean theroeom) is zero
they you're trying to divide by zero. (PLUS all those divides cost CPU time.) So instead....
```Mag = sqrt( XX+YY+ZZ+WW )
// As Mag is approaching zero (NUMBER is really close to zero, leave the original number alone!

if (Mag > 0.0001)
{
Mag = 1.0 / Mag
nX = X * Mag
nY = Y * Mag
nZ = Z * Mag
nW = W * Mag
}

```

If you pre-handled the reason for the zero divisor before the division, for that particular case, you never need the divide by zero! Leaving it alone is the same as multiplying by one. The Algebraic Law of Multiplicative Identity. X1=X

You can think of it another way. As you are approaching a zero divisor, the result is approaching infinity, thus the result is negligible therefore has the same effect as if doing nothing.

Ex: 8 / 8 = 1 8/4=2 8/2=4 8/1=8 8/0.5=16 8/0.1=80 8/0.0001=80,000 8/0.0000001=80,000,000 etc. until the result is over the limit of the processor, thus infinite!

This post has been edited by wildgoose: 04 September 2009 - 11:05 AM

### #10 jjl

• Engineer

Reputation: 1270
• Posts: 4,998
• Joined: 09-June 09

## Re: Dividing numbers into Zero

Posted 04 September 2009 - 11:46 AM

But your still not supposed to divide by zero, the result will give you where the limit is undefiened which will be an asymtope

### #11 NickDMax

Reputation: 2255
• Posts: 9,245
• Joined: 18-February 07

## Re: Dividing numbers into Zero

Posted 04 September 2009 - 01:30 PM

...you ever get the feeling someone is just messing with you?

Division by zero is undefined mathematically and generally results errors when done in code: example:
```int main(){
int a = 100;
int b = 0;
int c = a/b; //<-- crashes program
printf("%d",c);
return 0;
}
```

This results in an Exception 0xc0000094 -- integer divide by zero on windows.

So if you have a program and you "might" divide by zero then you may want to do a check to ensure that you don't:

int c = a / (b !=0 ? b : 1); -- will divide by 1 rather than zero

or int c = (b==0 ? 0 : a/; -- will return 0 rather than doing the div by zero.

If you are using floating point values than you can divide by a very very small number rather than zero -- which may be a totally wrong answer but it will not crash your program.

### #12 wildgoose

• D.I.C Regular

Reputation: 67
• Posts: 468
• Joined: 29-June 09

## Re: Dividing numbers into Zero

Posted 04 September 2009 - 03:04 PM

Quote

...you ever get the feeling someone is just messing with you?

Yep!

I thought I was being clear, even with two examples, but I guess not!

"As X approaches zero it becomes an "asymptote'" <-- IamASexy, watch your spelling on 'terminology' when you can!

NickDMax, your solution was less verbose but more clear!

My kids hate it when I 'help' them with their homework as I mention things like Divide by Zero may mean "Undefined" to you now, but when you get to Calculus, it means "More Work!"

Admittedly, my pre-check solutions is in that "More Work" category!

This post has been edited by wildgoose: 04 September 2009 - 03:12 PM

### #13 jjl

• Engineer

Reputation: 1270
• Posts: 4,998
• Joined: 09-June 09

## Re: Dividing numbers into Zero

Posted 04 September 2009 - 03:14 PM

I have a problem of being too lazy to fix words while im typing lol but I just felt like saying something about it sence were actually doing limits and continuity in my calc class

### #14 IngeniousHax

• |>|20-514<|{3|2

Reputation: 84
• Posts: 1,385
• Joined: 28-March 09

## Re: Dividing numbers into Zero

Posted 05 September 2009 - 12:15 AM

ImaSexy, on 4 Sep, 2009 - 02:14 PM, said:

I have a problem of being too lazy to fix words while im typing lol but I just felt like saying something about it sence were actually doing limits and continuity in my calc class

Me too (2nd time)... But otherwise, dividing by zero is either undefined or leads into negative or positive infinity, until you hit L'Hospitals Rule, in which case you can usually find an answer.

### #15 wildgoose

• D.I.C Regular

Reputation: 67
• Posts: 468
• Joined: 29-June 09

## Re: Dividing numbers into Zero

Posted 05 September 2009 - 01:00 AM

Jeepers! I think we can almost all agree that dividing by zero is a bad thing, and detrimental to program flow!

This is why the code we write should not be blindly written and expect to work. Error handling has to be incorporated into our code such as predictive results if a case of zero occurs! In most cases it can be pre-handled with special handling on a case by case basis. If you are dividing by zero, then either you have a programming error, or a case had been allowed to occur to reach a divide by zero operation.

I think enough said on this topic!