C Program to find Factors of a Number

In this tutorial, i am going to show you how to find factors of a number in c program with the help of For Loop, While Loop, Functions, and pointer.

All C Programs to find Factors of a Number

  • C Program to find Factors of a Number Using While Loop
  • C Program to find Factors of a Number Using For Loop
  • C Program to find Factors of a Number Using Functions
  • C Program to find Factors of a Number Using Pointer

C Program to find Factors of a Number Using While Loop

#include <stdio.h>
 
int main()
{
  int Number, i = 1; 
  printf("\n Please Enter number to Find Factors :- ");
  scanf("%d", &Number);
 
  printf("\n The Factors of a Number are: :- ");
  while (i <= Number)
   {
     if(Number%i == 0)
      {
        printf("%d  ", i);  
      }
    i++;
   }
  return 0;
}

The result of the above c program; as follows:

Please Enter number to Find Factors :- 10
The Factors of a Number are: :- 1  2  5  10  

C Program to find Factors of a Number Using For Loop

/* C Program to Find factors of a number */
#include <stdio.h>
 
int main()
{
  int i, Number; 
   
  printf("\n Please Enter any number to Find Factors :- ");
  scanf("%d", &Number);
 
  printf("\n Factors of the Given Number are :- ");
  for (i = 1; i <= Number; i++)
   {
     if(Number%i == 0)
        {
		 printf(" %d  ", i);
		}
   }
 
  return 0;
}

The result of the above c program; as follows:

Please Enter any number to Find Factors :- 20
Factors of the Given Number are :-  1   2   4   5   10   20  

C Program to find Factors of a Number Using Functions

/* C Program to Find Factors of a Number using Functions */
#include <stdio.h>
void Find_Factors(int);  
 
int main()
{
  int Number; 
   
  printf("\nPlease Enter number to Find Factors :- ");
  scanf("%d", &Number);
 
  printf("\nFactors of a Number are :- ");
  Find_Factors(Number); 
 
  return 0;
}
void Find_Factors(int Number)
{ 
  int i; 
  
  for (i = 1; i <= Number; i++)
   {
    if(Number%i == 0)
     {
       printf("%d ", i);
     } 
   }
}

The result of the above c program; as follows:

Please Enter number to Find Factors :- 40
Factors of a Number are :- 1 2 4 5 8 10 20 40 

C Program to find Factors of a Number Using Pointer

/* C Program to Find Factors of a Number using Pointers */
#include <stdio.h>
void Find_Factors(int *);  
 
int main()
{
  int Number, *P; 
   
  printf("\n Please Enter number to Find Factors :- ");
  scanf("%d", &Number);
 
  P = &Number;
  
  printf("\n Factors of a Number are :- ");
  Find_Factors(P); 
 
  return 0;
}
void Find_Factors(int *Number)
{ 
  int i; 
  
  for (i = 1; i <= *Number; i++)
   {
    if(*Number % i == 0)
     {
       printf("%d ", i);		
     }
   }
}

The result of the above c program; as follows:

Please Enter number to Find Factors :- 10
Factors of a Number are :- 1 2 5 10 

More C Programming Tutorials

a

Leave a Comment