Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Need help with logic part C++

Name: Anonymous 2007-03-03 20:11 ID:BL8afESO

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: Anonymous 2007-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 ?

#include<iostream>


using namespace std;

int main()
{
    int num=0;
    int cat;
   
    cout<<"Number                            Classification \n";
    cout<<"______________________________________________________\n";
   
    while (num++ < 30)
    {cout<<num<<"num \n";
    while
    num++;
    }
                            
    cout<<"\n";
    system("pause");
    return 0;
}

Name: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-03-03 22:54 ID:EUNrHuxV

>>7
I've done virtually no functional programming. Should I be worried that I understand this?

Name: Anonymous 2007-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"

Name: Anonymous 2007-03-04 4:33 ID:Ro/+5mpq

>>8

No, good code should explain itself.

Name: Anonymous 2009-03-06 5:39

That ring too many   images and names?

Name: Anonymous 2009-03-06 9:04


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?

Name: Anonymous 2009-03-06 10:53

>>7
import Maybe

printResult n pdivs =
   putStrLn $ show n ++ "\t" ++ fromJust (lookup (compare (sum pdivs) n) table)
   where
   table = zip [GT, EQ, LT] ["abundant", "perfect", "deficient"] 

properDivs n = filter ((==0) . mod n) [1..div n 2]

main = mapM_ (mapM_ $ \n -> printResult n $ properDivs n) [[20..30], [490..500], [8120..8130]]

Name: Anonymous 2010-12-21 10:11

Name: Anonymous 2011-02-04 19:44

Name: Anonymous 2012-03-23 23:41

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boyAll 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

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

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

All work and no play makes Jack a dull boyAll 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

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

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

All work and no play makes Jack a dull boyAll 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

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

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

All work and no play makes Jack a dull boyAll 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

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

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

All work and no play makes Jack a dull boyAll 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

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

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

All work and no play makes Jack a dull boyAll 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

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

All work and no play makes Jack a dull boy

All work and no play makes Jack a dull boy

Name: Anonymous 2012-03-25 21:42

>>1
Fucking nice post! Badabababa I'm lovin' it!

Name: Sgt.Kabu썾复kiman夷 2012-05-28 22:59

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

Don't change these.
Name: Email:
Entire Thread Thread List