Home

Published

- 1 min read

find factors of a number in c

img of find factors of a number in c

The solution for this is noted below

find factors of a number in c

Solution

   #include <stdio.h>
int main() {
    int num, i;
    printf("Enter a positive integer: ");
    scanf("%d", &num);
    printf("Factors of %d are: ", num);
    for (i = 1; i <= num; ++i) {
        if (num % i == 0) {
            printf("%d ", i);
        }
    }
    return 0;
}

Try other methods by searching on the site. That is if this doesn’t work