UncleCoder.com

UncleCoder.com

Free programming examples and instructions

C program to find the factors of a number

c program for how to find factors of a number

by Krishna viswambharan


Posted on 31 Oct 2017 Category: C Views: 146

Edited on 02 Jul 2018


C program to find the factors of a number

This program reads a  positive integer from the user and displays all the positive factors of that number. This program compiles successfully and output is also shown below.

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

    printf("Enter a positive integer: ");
    scanf("%d",&num);

    printf("Factors of %d are: \n", num);
    for(i=1; i <= num; ++i)
    {
        if (num%i == 0)
        {
            printf("%d\n ",i);
        }
    }
    getch();
    return 0;
}

output



Leave a Comment:


Advertisement