C program to find all factors of a number

In this example, you will learn to find all the factors of an integer entered by the user.

C Program to Display Factors of a Number

	
#include<stdio.h>  

int main()  
{  
    int num, count = 1;  
    
    printf("Enter a number\n");  
    scanf("%d", &num);  
    
    printf("Factors of %d are:\n", num);  
    
    while(count <= num)  
    {  
        if(num % count == 0)  
        {  
            printf("%d\n", count);  
        }  
        count++;  
    }  
    
    return 0;  
}  
	

Output :

	
Enter a number
55
Factors of 55 are:
1
5
11
55
	

Share your thoughts

Ask anything about this examples