mihainan

Lab3 PC - ex 2 (CA)

Oct 21st, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int nr, i, ok;
  7.     scanf("%d", &nr);
  8.     while(nr > 0)
  9.     {
  10.         ok = 1; //presupun ca este prim
  11.         for(i = 2 ; i <= nr/2; i++)
  12.         {
  13.             if(nr % i == 0)
  14.             {
  15.                 ok = 0; //clar nu este prim
  16.                 printf("%d ", i);
  17.             }
  18.         }
  19.         if(ok == 1)
  20.         {
  21.             printf("PRIM\n");
  22.         }
  23.         else
  24.         {
  25.             printf("\n");
  26.         }
  27.         scanf("%d", &nr);
  28.     }
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment