Advertisement
mauricioribeiro

C Primo - Não Recursivo

Feb 10th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. int soma = 0;
  5.  
  6. int Primo(int num)
  7. {  
  8.     int completo = 0, atual = 2, i,exato;
  9.     while(completo<num){
  10.         exato = 0;
  11.         for (i = 1; i < atual; i++){
  12.             if(atual%i==0){
  13.                 exato++;
  14.             }
  15.         }
  16.         if(exato==1){
  17.             printf("%d ", atual);
  18.             completo++;
  19.             soma +=atual;
  20.         }
  21.         atual++;
  22.     }
  23. }
  24.  
  25. int main()
  26. {
  27.     int n;
  28.     printf ("Digite um numero: ");
  29.     scanf("%d", &n);
  30.     Primo(n);
  31.     printf(" = ", soma);
  32.     getch();
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement