Skip to content

Instantly share code, notes, and snippets.

@FloydHsiu
Created October 25, 2016 04:00
Show Gist options
  • Save FloydHsiu/a773a230de23db421d42c6003087b63f to your computer and use it in GitHub Desktop.
Save FloydHsiu/a773a230de23db421d42c6003087b63f to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
int scale = 0;
int i = 0;
int j = 0;
int is_p = 0;
scanf("%d", &scale);
//calculate every int lower than scale
for(i=2; i<=scale; i++){
//Suppose i is prime number
is_p = 1;
//Check every number, exclusive of '1', lower than i will not be divisiable
for(j=2; j<i; j++){
if(i%j == 0){
//i is divisiable by j, so i is not prime number
is_p = 0;
break;
}
}
if(is_p == 1){
printf("%d\n", i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment