Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. bool primo(int np)
  5. //Recebe um numero e se ele for primo retorna verdadeiro, caso contrário falso.
  6. {
  7. int cont_div = 0;
  8. for (int a = 2; a <= np; a++) {
  9. if (np % a == 0) {
  10. cont_div++;
  11. }
  12. }
  13. return (cont_div == 1);
  14. }
  15.  
  16. void proximo_primo(int n)
  17. {
  18. for (int i = n-1; i >= 2; i--) {
  19. if (primo(i)) {
  20. printf("%d ", i);
  21. }
  22. }
  23. }
  24.  
  25. int main (void)
  26. {
  27. int n;
  28. scanf("%d", &n);
  29. proximo_primo(n);
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement