File: Stare vježbe/vjezbe07/45__prosti_faktori.c

  1. /*
  2.   45__prosti_faktori.c
  3.   Primjer koristenja rekurzivnih funkcijskih poziva
  4.   -----
  5.   Program ispisuje rastav unesenog broja na proste faktore
  6. */
  7.  
  8. #include <stdio.h>
  9.  
  10. int prost(int y, int i)
  11. {
  12. if(i>=y)
  13. return(i);
  14. else if(!(y%i)) {
  15. printf("%d*",i);
  16. return(prost(y/i, i));
  17. }
  18. else
  19. return(prost(y, i+1));
  20. }
  21.  
  22. int main()
  23. {
  24. int i;
  25. int x, y;
  26.  
  27. printf("Unesite broj: ");
  28. scanf("%d", &x);
  29. printf("\n%d = ", x);
  30.  
  31. if(x==1)
  32. printf("%d\n", x);
  33. if(x)
  34. printf("%d\n", prost(x,2));
  35. else
  36. printf("Unijeli ste nulu!\n");
  37.  
  38. return 0;
  39. }
  40.