Ghislain_Mike

Check prime numbers from a number to zero

Feb 12th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main() {
  5.     int num,i,j,c;
  6.  
  7.     printf("please enter the number?\n");
  8.     scanf("%d",&num);
  9.  
  10.     for (j=1;j<=num;j++){ // count from 1 to NUMBER
  11.         for (i=1,c=0;i<=j;i++){ //check for prime number and initialize c to zero
  12.             if (j%i==0){
  13.                 c++;
  14.             }
  15.         }
  16.         if (c==2){
  17.              printf("%d\n",j);
  18.         }
  19.     }
  20.  
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment