-
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;
}
-
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?
-
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.