Integer divisor function
1. Definition
The following function ouputs the divisors of an integer. Plus,
It tests whether it is prime.
2. Example in C language:
#include <stdio.h>
int main()
{
int number, rate;
printf("\n Enter an integer ?: --> ");
scanf("%d", &number);
//How many numbers will be written by line ?
printf("\n How many divisors would be displayed by line ?: --> ");
scanf("%d", &rate);
printf("\n");
printf("\n The divisors of %d are:\n", number);
printf("\n");
int n , k = 0 ;
for ( n = 1 ; n <= number ; n++ )
if ( number% n == 0 )
{
k++ ;
printf("%3d)%4d ", k, n);
if ( k % rate == 0 ) printf("\n");
}
// Plus ..
printf("\n\n The number %d has %d divisors. ", number, k);
if ( k == 2 )
{
printf("It is prime. \n");
}
else
{
printf("It is not prime. \n");
}
printf("\n");
return 0;
}