# Algorithm and Flowchart to find all the factors of an Integer

[559 views]

### What are factors of a number?

Factors of a Number are the whole numbers which on multiplication of them form that number. For Eg. Factor of 12 are 2,4,6,3. 2 X 6 = 12 and 4 X 3 = 12 and their vice versa.

Factors are the essential element in mathematics. It is used to solve various problems in mathematics and even in real life. To divide the elements into that factors. Like 5 \$20 make \$100 or even finding the average.

### What should be the approach for this problem ?

Try to collect as much data as we can like we are taking the factors of the number we know that by dividing them with factors they are purely divisible. We also know that the largest number divisible would be its half , so we can run the loop till half of the given digit and check its modulus with 1 to n/2 (n is the number whose factor we have to find)

## Pseudocode for Factors of a number:

Declare a variable n and i as integer; Read the number n; for i=1 to n/2 and increment i by 1 { check if(n%i==0) //modulo gives the remainder { print i } }

Here in this algorithm we declare 2 variables as integer one for storing the number and other for running the for loop. Then we read the variable n. We run the for loop form i=0 to n/2 incrementing i by 1.Then using the if statement checking if the number n is divisible by i or not for that we use modulo operator it gives the remainder if a number n is divided by modulo of that number i .If the modulo is 0 then print i.

## Implementation of the Factors of a number in C:

#include<stdio.h> int main() { int n, i; printf("Enter the number to find its factors:"); scanf("%d", & n); printf("Factors of the %d are: ", n); for (i = 1; i <= (n / 2); i++) { if (n % i == 0) { printf("%d ", i); } } }