C Program to display Positive factors of a number


This content was proof-read by Grammarly. You can Try Grammary for FREE

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.


Are you a .NET Developer planning to integrate GraphQL for .NET in your Application? Check out this book BUY & DOWNLOAD GRAPHQL.NET COOKBOOK
#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

%d bloggers like this: