Thread: C Assignment Help

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    1

    C Assignment Help

    I'm in college and I have to do an assignment on Abundant Numbers (Programmed in C).

    Assignment Details are pretty straight forward. Ask for a number determine if it is abundant.
    -Use "boolean" function to test a number for abundance.
    -use a function to control output and another for input.
    -An Abundant Number is a positive integer whose integer factors less than itself sum to a value greater than it.

    This is the Code I have so far:
    Code:
    #include <stdio.h>
    
    #include <math.h>
    
    
    
    int Input(int N)
    
    {
    
    	printf("Enter the Nth Abundant Number you wish to see: ");
    
    	scanf("%d", &N);
    
    	return(N);
    
    }
    
    
    
    int Calc(int N)
    
    {
    
    	int Sum, I, I2;
    
     
    
    	Sum = 0;
    
    	I2 = sqrt(N);
    
    
    
    	for (I = 1; I >= I2; I++)
    
    		if ((N % I) = 0) Sum += I + (N / I);
    
    
    
    	return(Sum);
    
    }
    
    
    
    int Check(int N, int Sum, int Abundancy)
    
    {
    
    	if (Sum > N)
    
    		Abundancy = 1;
    
    	else
    
    		Abundancy = 0;
    
    
    
    	return(Abundancy);
    
    }
    
    
    
    int Output(int Number, int Abundancy)
    
    {
    
    	if (Abundancy == 1)
    
    		printf("%d %s", Number, "is Abundant");
    
    	else
    
    		printf("%d %s", Number, "is not Abundant");
    
    }
    
    
    
    int main()
    
    {
    
    	/* Variables */
    
    	int N, Sum;
    
    	int Abundancy;
    
    	
    
    	/* Start Loop */
    
    	while (N != 0)
    
    	{
    
    		/* Input */
    
    		N = Input(N);
    
    		for(int I = N; I = (N - 10)or I <= 0; I--)
    
    		{
    
    			/* Calculate */
    
    			Sum = Calc(N);		
    
    
    
    			/* Determine Abundancy */
    
    			Abundancy = Check(N, Sum, Abundancy);		
    
    		
    
    			/* Output */
    
    			Output(N, Abundancy);
    
    		}
    
    	}	
    
    }
    Could someone help me figure out why it declares everything as not an abundant number?
    my test is 12. 1 + 2 + 3+ 4+ 6 = 16, 16 > 12, so it is abundant.

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    >> for (I = 1; I >= I2; I++)
    Why use I as variable name?! Review the loop condition.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 01:21 PM