I know I need to use a loop in this program but I have no idea what to use
problem
The proper divisors of an integer n are the positive integer divisors whose values are less than n. A positive integer is said to be a deficient, perfect, or abundant number if the sum of its proper divisors is, respectively, less than, equal to, or greater than the number. For example, 8 is deficient because its proper divisors are 1, 2, and 4, and 1 + 2 + 4 < 8; The integer 6 is perfect because its proper divisors are 1, 2, and 3, and 1 + 2 + 3 = 6; The integer 12 is abundant because its proper divisors are 1, 2, 3, 4, and 6, and
1 + 2 + 3 + 4 + 6 > 12. Write a program that classifies an integer n as being deficient, perfect, or abundant, for the following values of n:
n = 20 to 30 inclusive
n = 490 to 500 inclusive
n = 8120 to 8130 inclusive
Display your results in a tabular format similar to the following example:
Number classification
8 deficient
6 perfect
12 abundant
Name:
Anonymous2007-03-03 20:13 ID:BL8afESO
this is what I did so far which is useless. is this suposed to be a loop in a loop problem ?
while (num++ < 30)
{cout<<num<<"num \n";
while
num++;
}
cout<<"\n";
system("pause");
return 0;
}
Name:
Anonymous2007-03-03 20:33 ID:CbbEq8O3
>>2
i....don't even know what you expect that program to do. i highly doubt it does what you expect it to.
Name:
Anonymous2007-03-03 20:48 ID:BL8afESO
I know that is why I said I don't know where to start from. it is gonna be a loop in a loop but not sure how that would work.
Name:
Anonymous2007-03-03 21:04 ID:EUNrHuxV
Why don't you start by figuring out how to classify your integers first, and go from there?
Name:
Anonymous2007-03-03 21:09 ID:P+xM/6r/
use a real programming language like SML and you wouldnt run into these kinds of problems
Name:
Anonymous2007-03-03 22:17 ID:BENfLWO2
Hi there, I did your homework.
module Main
where
properDivisors n = [x|x<-[1..ceiling((fromInteger n)/2.0)], (rem n x) == 0]
data Classification = Deficient | Perfect | Abundant
classify x
| d > x = Abundant
| d < x = Deficient
| otherwise = Perfect
where d = sum $ properDivisors x
main =
let (numDefi, numPerf, numAbun) = foldr getCounts (0,0,0) $ map classify $ concat [[20..30], [490..500], [8120..8130]]
where getCounts x (d,p,a) = case x of { Deficient -> (d+1,p,a) ; Perfect -> (d,p+1,a) ; Abundant -> (d,p,a+1) } in
do
putStrLn "Classification: Number"
putStrLn "----------------------"
putStrLn $ "Deficient: " ++ show numDefi
putStrLn $ "Perfect: " ++ show numPerf
putStrLn $ "Abundant: " ++ show numAbun
Name:
Anonymous2007-03-03 22:54 ID:EUNrHuxV
>>7
I've done virtually no functional programming. Should I be worried that I understand this?
Name:
Anonymous2007-03-04 0:18 ID:T4HMXpui
Main:
output "Number : Classification"
for each in {{20...30},{490...500},{8120...8130}} -> Set
for each in Set -> Number
Classify Number -> Classification
output Number " : " Classification
stop
Classify:Number
0 -> Total
for each in {1...(Number-1)} -> Divisor
remains Divisor into Number -> Remainder
if Remainder = 0 add Divisor and Total -> Total
if Total = Number return "Perfect"
if Total > Number return "Abundant"
if Total < Number return "Deficient"
about doing realtime graphics Perl or Ruby start smaller though Try writing a text based adventure then you can make the pointers that I would in my classes even forbid anything outside of pen and paper Garbage?
Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy