Advertisement
18126

Day3(ex2)

Jul 8th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int main() {
  6.     int i,j,n;
  7.     printf("Enter N (where N is the max number you want prime numbers to): \n");
  8.     scanf("%d", &n);
  9.     printf("Prime numbers: ");
  10.     for(i = 2;i <= n;i++) {
  11.         int c = 0;
  12.         for(j = 1;j <= i;j++) {
  13.             if(i % j == 0) {
  14.                 c++;
  15.             }
  16.         }
  17.         if(c == 2) {
  18.             printf("%d ", i);
  19.         }
  20.     }
  21.     return EXIT_SUCCESS;
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement