Skip to content
Home » Program to Find Factors of a Number in C Using the do-while loop

Program to Find Factors of a Number in C Using the do-while loop

Learn about Program to Find Factors of a Number in C Using the do-while loop in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Program to Find Factors of a Number in C Using the do-while loop

Factors are the numbers that are multiplied together to get another number. Factors of 12 are 3 and 4, for example, because 34 = 12. A number’s factor will never be larger than half of the number.

Source code:

#include<stdio.h>
int main()
{
  int num, i=1;

  printf("Enter number: ");
  scanf("%d",&num);

  printf("Factors of %d are:\n", num);
  do
  {
    if(num%i==0) printf("%d\t",i);
    i++;
  } while (i<=num/2);

  return 0;
}

Output:

Enter number: 24
Factors of 24 are:
1 2 3 4 6 8 12

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
Program to find factor Using while loop
Program to find factors of a number in C using for loop