Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- void main() {
- //Get input
- printf("Enter number to count up to\n");
- long max = 2;
- scanf("%d",&max);
- max = max<2?2:max; //Lock input range
- //Setup of array
- char numbers[max];
- printf("I will count up to: %d", sizeof(numbers));
- memset(&numbers[0],0,sizeof(numbers));
- //Begin alg
- register char value = 0;
- for (int i=2;i<max;i++) {
- value = numbers[i];
- if(value==0) { //If prime
- printf("%d, ", i);
- for (int j=i;j<max;j+=i) { //sieve it
- numbers[j]=1;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment