Write a C program to find all divisors of a number.

Function Main
    Declare Integer n
    Declare Integer k
    Declare Integer r
    Output "Insert a number: "
    Input n
    Assign k = 1
    Output "All divisor of the number: "
    While k <= n
        Assign r = n mod k
        If r = 0
            Output k
        End
        Assign k = k + 1
    End
End

#include <stdio.h>

int main() {
    int n;
    int k;
    int r;
    printf("Insert a number: \n");
    scanf("%d", &n);
    k = 1;
    printf("All divisor of the number: \n");
    while (k <= n) {
        r = n % k;
        if (r == 0) {
            printf("%d\n", k);
        }
        k = k + 1;
    }
    return 0;
}

Insert a number:
15
All divisor of the number:
1
3
5
15

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.