Problem
Write a program in C to display all the positive factors of a number enter by the user.
How to find and display positive factors of a number in C ?
Below is a program in C demonstrating how to do it.
#include <stdio.h>
int main()
{
    int inputNumber, index;
    printf("Abundantcode.com coding sample\n");
    printf("Enter a Number :");
    scanf("%d",&inputNumber);
    printf("Positive factors of the number %d are below: ", inputNumber);
    for(index=1; index <= inputNumber; ++index)
    {
        if (inputNumber%index == 0)
        {
            printf("%d ",index);
        }
    }
    return 0;
}Output
Abundantcode.com coding sample
Enter a Number :5
Positive factors of the number 5 are below: 1 5
Leave a Reply