Guest User

Untitled

a guest
Jan 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. void main() {
  6. //Get input
  7. printf("Enter number to count up to\n");
  8. long max = 2;
  9. scanf("%d",&max);
  10. max = max<2?2:max; //Lock input range
  11. //Setup of array
  12. char numbers[max];
  13. printf("I will count up to: %d", sizeof(numbers));
  14. memset(&numbers[0],0,sizeof(numbers));
  15. //Begin alg
  16. register char value = 0;
  17. for (int i=2;i<max;i++) {
  18. value = numbers[i];
  19. if(value==0) { //If prime
  20. printf("%d, ", i);
  21. for (int j=i;j<max;j+=i) { //sieve it
  22. numbers[j]=1;
  23. }
  24. }
  25. }
  26. }
Add Comment
Please, Sign In to add comment