Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int ehprimo(int num){
- int x = 2;
- while (x <= num/2){
- if (num % x == 0){
- return 0; //FALSO, NAO EH PRIMO
- }
- x++;
- }
- return 1; //VERDADEIRO, EH PRIMO
- }
- int main()
- {
- int ini, fim, n;
- printf("Informe o intervalo a buscar os primos:");
- scanf("%d %d", &ini, &fim);
- printf("\nPrimos entre %d e %d:\n", ini, fim);
- for(n = ini; n <= fim; n++){
- if( ehprimo(n) ){
- printf("%d\n", n);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement