C Program to Find Prime Factors of Number using For Loop

C Program to Find Prime Factors of Number using For Loop

Write a Program to Find Prime Factors of Number using For Loop

// C Program to Find Prime Factors of Number using For Loop

#include <stdio.h>

void primefactors(int num)
{
    int count;

    printf("\nPrime Factors of %d are :--> ", num);
    for(count = 2; num > 1; count++)
    {
        for(; num % count == 0; )
        {
            printf("%d ", count);
            num = num / count;
        }
    }
    printf("\n");
}

int main()
{
    int num;

    printf("Enter a positive integer :--> ");
    scanf("%d", &num);

    primefactors(num);

    return 0;
}

Output:

Enter a positive integer :--> 98

Prime Factors of 98 are :--> 2 7 7