C Program to Find Prime Factors of Number using While Loop
Write C Program to Find Prime Factors of Number using While Loop
//Write C Program to Find Prime Factors of Number using While Loop #include <stdio.h> void primefactors(int num) { int count; printf("\nPrime Factors of %d are :--> ", num); for(count = 2; num > 1; count++) { while(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