Divisor or factor

X is a factor or divisor of N if and only if N % X == 0 i.e. Remainder should be zero.

X should divide N without leaving a remainder.

Any number can be expressed in following format,

Number = Quotient * Divisor + Remainder.

Pictorial Explanation

Factor of a number




Example

3 is not a factor of 10.

In Q * D + R form,

10 = 3 * 3 + 1

Here,

Q = 3

D = 3

R = 1

Here, R = 1 that means 3 is not a factor or divisor of 10.

4 is not a factor of 10 because,

10 = 4 * 2 + 2 (R != 0)

2 is a factor of 10 because,

10 = 5 * 2 + 0 (R == 0)




Algorithm

If N % X == 0

     Print “X is a divisor or factor of N”

Else

     Print “X is not a divisor or factor of N”




Program

Example

/******************************************
* Get two integers from user say N,X     *
* tell whether X is a factor of N or Not *
******************************************/
#include<stdio.h>

int main()
{
    int N,X;
    
    printf("Enter N and X\n");
    
    scanf("%d%d",&N,&X);
    
    if(N % X == 0)
        printf("%d is a factor of %d\n",X,N);
    else
        printf("%d is not a factor of %d\n",X,N);
        
    return 0;
}