Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

16.44 LADA, els Develop a C program that finds all prime numbers from 1 to 1000, using the Sieve of Eratosthenes method. This method works

image text in transcribed
image text in transcribed
image text in transcribed
16.44 LADA, els Develop a C program that finds all prime numbers from 1 to 1000, using the "Sieve of Eratosthenes" method. This method works as follows a) Create a boolean array of 1000 elements with all elements initialized to true. The array indices correspond to numbers from 1 to 1000 whereas the array value corresponds to the state of that number (prime or not). For instance, if the state of the 10th array element is set to false, then number 10 is not a prime b) Starting from array element corresponding to number 4, make all elements corresponding to multiples of two equal to false. c) Repeat for elements that are multiples of three, four, eto When this process is complete the array elements that are equal to one indicate prime numbers. Print all primes from 1-1000. Your program should use the following functions void init(bool x int size, bool val) // to initiate an array to value val vold print Prime (bool xt. inter print prime Inumbers as indicated by x void no primes (bool xD). Int size, int base) // sets all multiple of base to talne Output 23 57 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 612 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 main.c 2 #include 3 #include 4 #include 5 #define S 1000 6 7 void init(bool x[], int size, bool val); 8 void printPrimes (bool x[], int size); 9 void noprime (bool x[], int size, int base); 10 11 int main(void) { 12 13 // your code goes here 14 ) 15 16 void init(bool x[], int size, bool val){ 17 W initializes boolean array to the value val. 18 19 20 void printPrimes (bool x[], int size) { 21 main.c 10 11 int main(void){ 12 13 // your code goes here 14 ) 15 16 void init(bool x[], int size, bool val){ 17 // initializes boolean array to the value val. 18) 19 20 void printPrimes (bool x[], int size) { 21 22 // prints only the prime numbers in x 23 ) 24 25 void noPrime(bool x[], int size, int base) { 26 // sets all multiples of base to not be primes 27 ) 28 29

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions