Your code works just fine if you remove this triangularNum
:
#include <stdio.h>
int main()
{
int a, n;
scanf("%d", &n);
for (a=2; a<=n; ++a)
{
while(n%a==0)
{
printf("%d\t", a);
n = n/a;
}
}
}
solved Find all prime factors of a given number