Thread: Perfect Numbers

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

    Question Perfect Numbers

    I need to make a program using a module ( two functions, one main and second the calculations)... The program has to tell a perfect numbers between 1 and 1000.
    This is what i have now. It gives me an error


    LINE 3: error: too few arguments to function `int perfect(int, int, int)'
    LINE 15: error: at this point in file

    LINE 3: error: too few arguments to function `int perfect(int, int, int)'
    LINE 16: error: at this point in file

    LINE 3: error: too few arguments to function `int perfect(int, int, int)'
    LINE 17: error: at this point in file

    So what I'm trying to do is to use the "b" "a" to print in the main function, how can i fix it.


    Code:
    #include<stdio.h>
    
    int perfect( int a, int b, int c); /*function prototype*/   /*LINE 3*/
    
    /*function main begins program execution */
    
    int main(void)
    {
       
      
    printf("This program will tell you the perfect numbers between 1 and 1000:\n");
    
        printf("\n %d  Perfect number\n",perfect(b));  /*LINE 15*/
        printf("\n Factors of %d are:\n",perfect(b));    /*LINE 16*/
        printf("%d\n",perfect(a));                                /*LINE 17*/
    return 0;/*indicates succeessful termination */
    }
    
    /*Function perfect definition */
    
    int perfect(int a,int b,int c)
    {
    for(b=1;b<=1000;b++) //checks for 1 to 1000 for perfect numbers
    {
    a=1; //initialized to check the factor from 1 to n
    c=0; // to check the sum of factors
    while(a<b)
    {
    if(b%a==0)
    c=c+a; //if i is a factor of n, i added to s
    a++; // in all conditions
    }
    if(c==b)// if n is a perfect no:
    {
    a=1;
    while(a<b)
    {
    if(b%a==0)
    printf("%d\n",a);
    a++;
    }
    }
    }
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    The compiler tells you: hey, you're passing too few arguments to this function!

    You defined your function to take three arguments (int a, int b, int c).

    You call your function with one argument (first time b, second time b again, and last time a).

    What do you think the problem is?

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Declare the variables you need in a function, inside that function. You don't need to try and borrow variables from main if that's what your plan was.

    Or perhaps your plan was to call it three times, to take care of the three parameters. Well it doesn't work that way either.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  3. Perfect Number Problem
    By TrazPFloyd in forum C++ Programming
    Replies: 21
    Last Post: 10-20-2002, 11:09 AM
  4. Line Numbers in VI and/or Visual C++ :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 02-10-2002, 10:54 PM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM

Tags for this Thread