# How to find the proper divisor?

• 07-24-2002
yusiye
How to find the proper divisor?
The problems says "a program will find the sum of the proper divisors of a give number n. The proper divisors on n are the numbers less than n that divides it evenly, they do not include n itself." I have no idea for this program, which function should i use?
• 07-24-2002
stormbringer
use modulo

Code:

```if ((x % y) == 0)     is divisor else   ain't```
• 07-24-2002
Crimpy
Just loop from Div = N - 1 to 1 and check if that N % Div is zero. If it is then print Div. Feel free to use my code as an example, but you aren't allowed to use it for any educational credits.
Code:

```/* (c) Copyright 2002 Daniel Raxter, All Rights Reserved. */ #include <stdio.h> #include <stdlib.h> void ListProperDivs (int N) {   int Div = N;   while (--Div > 0){     if ((N % Div) == 0)       printf ("%d ", Div);   } } int main (void) {   int N;   printf ("Enter a number: ");   if (scanf ("%d", &N) != 1){     fprintf (stderr, "Bad Input\n");     exit (EXIT_FAILURE);   }   /* Okay so far */   ListProperDivs (N);   return (EXIT_SUCCESS); }```
• 07-24-2002
Cshot
And you can loop through 1...n/2, since anything greater than n/2 is not possible.

Also the code above does not find the sum. But you can implement that easily.
• 07-24-2002
Crimpy
Oops, that should teach me to read threads more carefully. But as Cshot said, it's a trivial change so I won't repost the code.
• 07-24-2002
yusiye
I don't need anyone to coding for me. i need idea of this program
• 07-24-2002
yusiye
Code:

```#include <stdio.h> #include <stdlib.h> void List (int N); int N = 0; void main (void) {   while (N < 40)   {     N++;     printf("\n%d = ", N);     List (N);   } } void List (int N) {   int Div = N;   while (--Div > 0){     if ((N % Div)== 1 )       printf ("%d ", Div);   } }```