Advertisement
bombardelli

NumeroPrimoAlgoritmo

Apr 23rd, 2019
104
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 ehprimo(int num){
  5. int x = 2;
  6. while (x <= num/2){
  7. if (num % x == 0){
  8. return 0; //FALSO, NAO EH PRIMO
  9. }
  10. x++;
  11. }
  12. return 1; //VERDADEIRO, EH PRIMO
  13. }
  14.  
  15. int main()
  16. {
  17. int ini, fim, n;
  18. printf("Informe o intervalo a buscar os primos:");
  19. scanf("%d %d", &ini, &fim);
  20. printf("\nPrimos entre %d e %d:\n", ini, fim);
  21. for(n = ini; n <= fim; n++){
  22. if( ehprimo(n) ){
  23. printf("%d\n", n);
  24. }
  25. }
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement