Jvsierra

Resolução

Mar 19th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. int main()
  4. {
  5.     int n1, n2, i, cont = 0, j, primos = 0;
  6.  
  7.     printf("Digite n1 e n2:\n");
  8.     scanf("%d %d", &n1, &n2);
  9.  
  10.     while(n1 != 0 && n2 != 0)
  11.     {
  12.  
  13.         while(n1 <= n2)
  14.         {
  15.  
  16.             j = 1;
  17.  
  18.             while(j <= n1)
  19.             {
  20.                 if(n1 % j == 0)
  21.                     cont++;
  22.  
  23.                 j++;
  24.             }
  25.  
  26.             if(cont <= 2)
  27.                 primos++;
  28.  
  29.             cont = 0;
  30.  
  31.             n1++;
  32.         }
  33.  
  34.         printf("%d primos entre n1 e n2.\n", primos);
  35.  
  36.         primos = 0;
  37.  
  38.         printf("Digite n1 e n2:\n");
  39.         scanf("%d %d", &n1, &n2);
  40.     }
  41.  
  42.     getch();
  43. }
Advertisement
Add Comment
Please, Sign In to add comment