File: Stare vježbe/vjezbe06/35__funkcije.c

  1. /*
  2.   35__funkcije.c
  3.   Prvi program koji koristi funkcije.
  4. */
  5.  
  6. #include <stdio.h>
  7.  
  8. int ucitaj_broj ()
  9. {
  10. int broj;
  11.  
  12. scanf ("%d", &broj);
  13. return broj;
  14. }
  15.  
  16.  
  17. int broj_djelitelja ( int broj )
  18. {
  19. int total=0, i;
  20.  
  21. if (broj <= 0) return 0;
  22.  
  23. for (i=1; i<broj/2+1; i++)
  24. if (!(broj%i)) total++;
  25.  
  26. return total+1;
  27. }
  28.  
  29.  
  30. void ispisi_broj ( int broj, int koliko_djelitelja )
  31. {
  32. printf ("Broj %d ima %d djelitelja.\n", broj, koliko_djelitelja);
  33. }
  34.  
  35.  
  36. int main ()
  37. {
  38. int n, n_djel;
  39.  
  40. n=ucitaj_broj();
  41. n_djel=broj_djelitelja (n);
  42. ispisi_broj (n, n_djel);
  43.  
  44. return 0;
  45. }
  46.