14 Replies - 1305 Views - Last Post: 05 September 2009 - 01:00 AM Rate Topic: -----

#1 leizyl  Icon User is offline

  • New D.I.C Head

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

Dividing numbers into Zero

Post icon  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  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 89
  • View blog
  • 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.

Please post like this:
Posted Image
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

Was This Post Helpful? 0
  • +
  • -

#3 syfran  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 83
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#4 moopet  Icon User is offline

  • binary decision maker
  • member icon

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

Re: Dividing numbers into Zero

Posted 04 September 2009 - 05:08 AM

View Postsyfran, 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;
}



Nice, but it asked about dividing _into_ zero

 
int devIntoZero(double myNutsAreHuge)
{
   return 0; 
}



will give a far more accurate result
Was This Post Helpful? 0
  • +
  • -

#5 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

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

Re: Dividing numbers into Zero

Posted 04 September 2009 - 05:31 AM

View Postsyfran, 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!


Back to topic

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.
Was This Post Helpful? 0
  • +
  • -

#6 Nizbel99  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#7 syfran  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 83
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#8 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1270
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#9 wildgoose  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 67
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#10 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1270
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#11 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • 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/B); -- 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.
Was This Post Helpful? 0
  • +
  • -

#12 wildgoose  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 67
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#13 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1270
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#14 IngeniousHax  Icon User is offline

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

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

Re: Dividing numbers into Zero

Posted 05 September 2009 - 12:15 AM

View PostImaSexy, 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.
Was This Post Helpful? 0
  • +
  • -

#15 wildgoose  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 67
  • View blog
  • 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!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1