Advertisement
tonygms3

Question 10 Assignment

Dec 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int counter,j, num1, num_prime;
  6.  
  7.     printf ("Enter a number:\n");
  8.     scanf ("%d", &num1);
  9.  
  10.     for (counter=2 ; counter <= num1 ; counter++){
  11.             if (num1 % counter == 0){
  12.                 num_prime = 1 ;
  13.                 for ( j = 2 ; j <= counter/2 ; j++){
  14.                     if (counter % j == 0){
  15.                         num_prime = 0 ;
  16.                         break;
  17.                     }
  18.                 }
  19.  
  20.                 if (num_prime == 1){
  21.                     printf("%d\n", counter);
  22.                 }
  23.             }
  24.     }
  25.     return 0;
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement