C program to find all factors of a number :
Write a C program to input a number from user and find all factors of the given number using for loop. How to find factors of a number in C program. Logic to find all factors of a given number in C programming.
Example
Input
Input number: 12
Output
Factors of 12: 1, 2, 3, 4, 6, 12
What is factor of a number?
Factor of any number is a whole number which exactly divides the number into a whole number without leaving any remainder. For example: 2 is a factor of 6 because 2 divides 6 exactly leaving no remainder.
Program to find factors of any number code :
#include<stdio.h>
int main()
{
int n,i,p;
printf("Enter the number ");
scanf("%d",&n);
printf("factors %d : ",n);
for(i=1;i<=n;i++){
p=n%i;
/// or if(n%10==0)
if(p==0){
printf("%d, ",i);
}
}
return 0;
}
output :
No comments