Need help on the homework (if statements)

This is a discussion on Need help on the homework (if statements) within the C++ Programming forums, part of the General Programming Boards category; I'm having a trouble to make a program that can distinguish an "abundant" number. Here's the question: Arup really cares ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    32

    Question Need help on the homework (if statements)

    I'm having a trouble to make a program that can distinguish an "abundant" number. Here's the question:


    Arup really cares about divisibility. He especially likes numbers that have lots of divisors. In particular, he likes numbers with proper divisors that sum to greater than the number itself. These numbers are called, “abundant numbers.” A proper divisor of a number is any number strictly less than it that divides evenly into it. For example, 6 is a proper divisor of 12, but 12 is not. 12 is an example of an abundant number because 1+2+3+4+6 = 16 and 16 is greater than 12. As this example shows, one way to find out all the proper divisors of a number is to try each integer (starting at 1) out until you reach the number divided by 2. (It’s impossible for any number in between 7 and 11 to divide evenly into 12 because it is guaranteed that the result of the division is less than 2 since we are dividing by a greater number, and greater than 1, since we are not dividing by the number itself.)

    Input Specification
    1. The first integer line of the file will be a positive integer, n (less than 1000), indicating the number of test cases in the file.
    2. The next n lines will contain a single positive integer each (less than 10000), with the number you are to determine is abundant or not for that test case.

    This is what I have so far:

    Code:
    #include <stdio.h>        
    int main () {
    FILE *kam;
    int numb, numcases;
    
      kam = fopen("numbers.text", "r");
        
        fscanf(ifp, "%d", &numcases);
        
        for (numb=1; numcases >= numb; numb++)
           {
                if ...

    I know it involves with the if statements, but I'm having trouble to make the conditions to print out whether a number is an abundant or not.

  2. #2
    Registered User
    Join Date
    Sep 2009
    Posts
    32
    *fscanf(kam, "%d", &numcases)

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You need to 1) read a number 2) find the divisors 3) add up the divisors (you do this at the same time as 2) 4) compare the sum with the number 5) print out appropriately.

  4. #4
    Registered User
    Join Date
    Oct 2009
    Posts
    1
    Hy! I'm having a trouble to run a program. I have error: Unable to open include file 'graphics.h'
    Thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 11:42 AM
  3. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 12:36 PM
  4. Homework
    By kermi3 in forum C Programming
    Replies: 10
    Last Post: 09-27-2001, 05:49 PM
  5. Homework
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 09-10-2001, 02:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21