Advertisement
Guest User

Untitled

a guest
May 24th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int primos (int n);
  5.  
  6. int main()
  7. {
  8. int n;
  9. printf ("Digite um numero n: \n");
  10. scanf ("%d", &n);
  11.  
  12. printf ("\n \nO numero de primos no intervalo entre 2 e n e': %d", primos (n));
  13. }
  14.  
  15. int primos (int n)
  16. {
  17.  
  18. int i, count=0, div,j;
  19. for (i=2;i<=n;i++)
  20. {
  21. div=0;
  22. for (j=1;j<=i;j++)
  23. {
  24. if (i%j==0)
  25. {
  26. div++;
  27. }
  28. }
  29. if (div==2)
  30. {
  31. count++;
  32. }
  33. }
  34. return count;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement