C Program to Find All Factors of Number Last Updated : 07 Aug, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will learn to write a C program to print all distinct divisors of a number n. Factors of a number are the positive integers that divide the number without leaving a remainder. For example, for n = 10, the factors will be 1, 2, 5 and 10. Note: This problem is different from finding all prime factors. Recommended PracticeCount Numbers in RangeTry It!A Simple Solution to find all the factors of a number is to iterate all the numbers from 1 to n check if the current number divides n and print the current number. C Program to Display Factors of a Number C // C implementation of Naive // method to print all divisors #include <stdio.h> // Function to print the divisors void printDivisors(int n) { for (int i = 1; i <= n; i++) if (n % i == 0) printf("%d ", i); } // Driver code int main() { printf("The divisors of 100 are: "); printDivisors(100); return 0; } OutputThe divisors of 100 are: 1 2 4 5 10 20 25 50 100 Complexity AnalysisTime Complexity: O(n)Auxiliary Space: O(1)We can optimize this time complexity to O(sqrt(n)) by observing that all the divisors are present in pairs. For example if n = 100, then the pairs of divisors are: (1,100), (2,50), (4,25), (5,20), (10,10). Refer to the article Find all factors of a Natural Number for O(sqrt(n)) solution. But this solution will not print the factors in the sorted order. Please refer to the article Find all divisors of a natural number | Set 2 for an O(sqrt(n)) solution that prints divisors in sorted order. Comment More infoAdvertise with us Next Article C Program to Find minimum sum of factors of number K kartik Follow Improve Article Tags : C Programs C Language C Misc Programs Similar Reads C Program for efficiently print all prime factors of a given number Given a number n, write an efficient function to print all prime factors of n. For example, if the input number is 12, then output should be "2 2 3". And if the input number is 315, then output should be "3 3 5 7". First Approach: Following are the steps to find all prime factors. 1) While n is divi 5 min read C Program for Find sum of odd factors of a number Write a C program for a given number n, the task is to find the odd factor sum. Examples: Input : n = 30Output : 24Explanation: Odd dividers sum 1 + 3 + 5 + 15 = 24 Input : 18Output : 13Explanation: Odd dividers sum 1 + 3 + 9 = 13 C Program for Find sum of odd factors of a number using Prime Factori 3 min read C Program to Find minimum sum of factors of number Write a C program for a given number N, the task is to find the minimum sum of its factors. Examples: Input : 12Output : 7Explanation: Following are different ways to factorize 12 andsum of factors in different ways.12 = 12 * 1 = 12 + 1 = 1312 = 2 * 6 = 2 + 6 = 812 = 3 * 4 = 3 + 4 = 712 = 2 * 2 * 3 2 min read C Program for Find largest prime factor of a number Given a positive integer 'n'( 1 <= n <= 1015). Find the largest prime factor of a number. Input: 6 Output: 3 Explanation Prime factor of 6 are- 2, 3 Largest of them is '3' Input: 15 Output: 5Method 1: The approach is simple, just factorise the given number by dividing it with the divisor of a 3 min read JavaScript Program to Find All Factors of a Natural Number Finding all factors of a natural number is a common task in programming and mathematics. A factor of a number is an integer that can be multiplied by another integer to produce the original number. In this article, we will discuss various approaches to finding all factors of a natural number using J 2 min read Smallest integer which has n factors or more Given n, find the smallest integer which has n factors or more. It may be assumed that the result is less than 1000001. Examples: Input : n = 3 Output : 4 Explanation: 4 has factors 1, 2 and 4. Input : n = 2 Output : 2 Explanation: 2 has one factor 1 and 2. There are many methods to calculate the nu 15 min read Like