Write a C Program to Find the Factors of the Inputted Number

Write a program in the C programming language to find the factors or divisible of the inputted number. Make this program by using ‘ for loop ‘. It also tells the total number of factors of the inputted number. Below is the solution of the program –

/* C program to find factors or divisible of a number */

#include<stdio.h>
void main()
{
     int n,i,rd,sum=0;

     printf("Enter any number \n");
     scanf("%d",&n);

     printf(" Factors of %d are - \n",n);
     for(i=1;i<=n;i++)
     {
             rd=n%i;
             if(rd==0)
             {
                     printf("\t %d",i);
                     sum=sum+1;
             }
     }

     printf("\n \n %d is divible by %d numbers",n,sum);
     getch();
}

Input – 15
Output – Factors of 15 are – 1   3   5   15
15 is divisible by 4 numbers

yashan has written 70 articles

One thought on “Write a C Program to Find the Factors of the Inputted Number

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>