Find Factors of Number usnig C language

Find factors here below is full code to compile code here is link:https://www.programiz.com/online-compiler/0qx0OWWfJ5sOv

Code:

#include <stdio.h>

int main() {
    int fac, num;   // fac = factor, num = number entered by user

    // Ask user to enter a number
    printf("Enter a number: ");
    scanf("%d", &num);

    // Display message
    printf("Factors of %d are: ", num);

    // Loop starts from 1 and goes till the number
    // Because a factor can never be greater than the number itself
    for (fac = 1; fac <= num; fac++) {

        // If num is divisible by fac, then fac is a factor
        if (num % fac == 0) {
            printf("%d, ", fac);   // Print the factor
        }
    }

    return 0;  // Program ends successfully
}

This is full code i made it myself

Leave a Comment

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