1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Case study :d

Discussion in 'C' started by Luisa Mia Peralta, Sep 25, 2011.

  1. Luisa Mia Peralta

    Luisa Mia Peralta New Member

    Joined:
    Sep 25, 2011
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    1) The proper divisor of an integer N are the positive divisor less than N, a positive integer is said to be DEFiCiENT, PERFECT, or ABUNDANT numbers if the sum of it's proper divisor is less than, equal to or greater than the number respectively. Write a program using function call by reference to input integer N and call function COMPUTE to determine of integer N is DEFiCiENT, PERFECT or ABUNDANT.

    EXAMPLE :
    Input n: 8
    Proper divisors are 1,2,4
    sum of proper divisors: 1 + 2 + 4 = 7
    7<8 is DEFiCiENT


    Input N: 6
    Proper Divisors are 1,2,3
    Sum of proper divisors; 1 + 2 + 3 = 6
    6=6 is PERFECT


    Input N: 12
    Proper divisors are 1, 2, 3, 4,6
    Sum of proper divisors : 1 + 2 + 3 + 4 + 6 = 16
    16 > 12 ABUNDANT

    Kindly answer this :))
     
  2. DRK

    DRK New Member

    Joined:
    Apr 13, 2012
    Messages:
    44
    Likes Received:
    3
    Trophy Points:
    0
    Code:
    void COMPUTE(int N)
    {
    	int i, sum = 0;
    	
    	printf("Proper divisors are: ");
    	for (i = 1; i < N; i++)
    	{
    		if (N % i == 0)
    		{
    			if (i > 1)
    			{
    				printf(", ");
    			}
    			printf("%d", i);
    		}
    	}
    	printf("\n");
    
    	printf("Sum of proper divisors: ");
    	for (i = 1; i < N; i++)
    	{
    		if (N % i == 0)
    		{
    			if (i > 1)
    			{
    				printf(" + ");
    			}
    			printf("%d", i);
    			sum += i;
    		}
    	}
    	printf(" = %d\n", sum);
    
    	if (sum < N)
    	{
    		printf("%d < %d is DEFICIENT\n", sum, N);
    
    	}
    	else if (sum > N)
    	{
    		printf("%d > %d is ABUNDANT\n", sum, N);
    	}
    	else
    	{
    		printf("%d == %d is PERFECT\n", sum, N);
    	}
    
    }
     
  3. Luisa Mia Peralta

    Luisa Mia Peralta New Member

    Joined:
    Sep 25, 2011
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    thanks a lot DRK ! i'll try this one on my turbo c :DD
     
  4. Jacobhine

    Jacobhine New Member

    Joined:
    Aug 8, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    I will also try for this, thanks DRK
     

Share This Page