I wrote a code below to find out the prime factors using recursion. it runs fine but terminates with a message: primfactor.exe has stopped working. check for online solution.. any idea why so?

Code:/*prime factor by recursion*/ #include<stdio.h> int rec (int,int); /* this semi colon is must*/ int main(void) { int n; printf("Enter any positive integer for prime factorization ? "); scanf("%d",&n); rec(n,2); return (0); } int rec(int n, int l) { while (1) { if (n%l==0) { printf("%d ",l); n=n/l; } else { if (n==l) break; rec(n,l+1); } } return (0); }