Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Calcula cuantos numeros primos hay en un intervalo
- #include <stdio.h>
- typedef enum {false, true} boolean;
- boolean comprobarPrimo(int numero){
- int z, a;
- a = 0;
- for(z = 1; z <= numero; z++){
- if(numero % z == 0){
- a++;
- }
- }
- if (a <= 2){
- return true;
- }
- else{
- return false;
- }
- }
- int main(){
- int t, i, k;
- int counter = 0;
- int num1, num2;
- boolean primo;
- primo = false;
- scanf("%d",&t);
- for (i = 0; i < t; i++){
- scanf("%d %d",&num1, &num2);
- for (k = num1; k <= num2; k++){
- primo = comprobarPrimo(k);
- if (primo == true){
- counter++;
- primo = false;
- }
- }
- printf("%d \n",counter);
- counter = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement