Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. // Calcula cuantos numeros primos hay en un intervalo
  2.  
  3. #include <stdio.h>
  4.  
  5. typedef enum {false, true} boolean;
  6.  
  7. boolean comprobarPrimo(int numero){
  8.    
  9.     int z, a;
  10.    
  11.     a = 0;
  12.    
  13.     for(z = 1; z <= numero; z++){
  14.         if(numero % z == 0){
  15.             a++;
  16.         }
  17.     }
  18.     if (a <= 2){
  19.         return true;
  20.     }
  21.     else{
  22.         return false;
  23.     }
  24.  
  25.            
  26. }
  27.  
  28. int main(){
  29.     int t, i, k;
  30.     int counter = 0;
  31.     int num1, num2;
  32.     boolean primo;
  33.    
  34.     primo = false;
  35.    
  36.     scanf("%d",&t);
  37.    
  38.     for (i = 0; i < t; i++){
  39.        
  40.         scanf("%d %d",&num1, &num2);
  41.        
  42.         for (k = num1; k <= num2; k++){
  43.             primo = comprobarPrimo(k);
  44.             if (primo == true){
  45.                 counter++;
  46.                 primo = false;
  47.             }
  48.         }
  49.        
  50.         printf("%d \n",counter);
  51.         counter = 0;
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement