"Il y a peu de choses qui me soient impossibles..."
"Il y a peu de choses qui me soient impossibles..."
"Il y a peu de choses qui me soient impossibles..."
Ranajoy Saha wrote:I got it! I will be calc += j Right! Cause each time when the rem == 0 is true the calc counter is increasing by the number it self it is not adding up the factors.
But still I am getting the out put as "This number 1 is a perfect number." I cant make out why!
"Il y a peu de choses qui me soient impossibles..."
"Il y a peu de choses qui me soient impossibles..."
Junilu Lacar wrote:
If you do make a comment about your reason for not starting your loop from 1 because you know it's not a perfect number, then you might as well think about your decision about the range of values you iterate through to check for proper divisors of a number. Why are you checking more than you need to? If you think about it, proper divisors of a number can only be up to half the number at most.
"Il y a peu de choses qui me soient impossibles..."
Stevens Miller wrote:It's one thing to write a program that produces output you can verify; that includes any and all optimizations you can show, by extrinsic evidence, are consistent with the purpose of the program. It's another thing entirely to write a program that meets a particular spec.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:Suppose you were asked to write a factorial program, what would you do for 0!?
The fact is that it's defined to be 1 (the best reason that I know of being that for every positive value of n, n! = n*(n-1)!), but I would say that it's equally valid for a person to write a program that throws an exception if 0 is supplied, or simply returns 1, because it doesn't fit the general pattern.
Along the same lines: is 1 a prime number? If you use the definition 'a number that is divisible only by itself and 1' then the answer must be true, yes? But it ain't.
The fact is that 0 and 1 are often exceptions to a general rule, so I think it's reasonable to use exceptional logic to deal with them.
"Il y a peu de choses qui me soient impossibles..."
Junilu Lacar wrote:Stevens,
Both points are moot in the absence of a clear statement of the requirement. I do get your point about including 1 in the test range if the assignment/spec is clearly stated and interpreted the way you say. However, the leap from getting an answer via calculation vs. hard-coding the answer is hardly reasonable nor defensible, at least not with any professors I know
(I don't know any law professors though - that might be a different story)
As for proper divisors being at most half the dividend, I don't see how the decision to use that mathematical fact can keep you from meeting the perfect number goal, no matter how it's stated.
"Il y a peu de choses qui me soient impossibles..."
Winston Gutkowski wrote:Along the same lines: is 1 a prime number? If you use the definition 'a number that is divisible only by itself and 1' then the answer must be true, yes? But it ain't.
Stevens Miller wrote:The "correctness" of the code depends on the spec. I would say it is, at the moment, unknown, rather than moot.
Paul Clapham wrote:And yes, Stevens, mathematics and law are very similar in the way they work. I've always considered lawyers to be mathematicians who suffer from extroversion.
"Il y a peu de choses qui me soient impossibles..."
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |