Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 4 Q.5 Prime Numbers Lookup Description Lab4-5. Prime Numbers Lookup Complete the given program to print all prime numbers in user input integer range

Lab 4 Q.5 Prime Numbers Lookup

Description

Lab4-5. Prime Numbers Lookup

Complete the given program to print all prime numbers in user input integer range [start, end]. We assume 2 <= start <= end <= 100 and no input validation is needed. After printing the prime(s), show also the number of primes printed.

Be reminded that you have completed a program to do a lucky draw lookup before in Lab 3 Q.3. You may find the program very helpful as a reference.

You may realize we have already given you a lookup table isPrime[] in the main.c code. How can you use it to determine whether a number is prime or not?

Note: After the user input, the program should print [start, end] prime1 prime2 ... primeN (N) where N is the number of primes within the range.

Deadline: 24 Feb, 2023 (Fri)

Input

The positive integers, a and b, separated by a space.

Output

The numbers in the format,

"[a b]: ()"

Pay attention to the spaces.

Sample Input 1

2 100

Sample Output 1

[2, 100]: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 (25) 

Sample Input 2

35 36

Sample Output 2

[35, 36]: (0) 

Sample Input 3

37 37

Sample Output 3

[37, 37]: 37 (1) 

Sample Input 4

17 89

Sample Output 4

[17, 89]: 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 (18) 

Sample Input 5

30 40

Sample Output 5

[30, 40]: 31 37 (2) 

/* include header file */ #include

/* starting point of this C program */ int main(void) { // GIVEN an initialized array isPrime[] with proper initializers each element in the array, e.g., isPrime[3], isPrime[4], represents that the corresponding integer index is a prime number or not

// DO NOT CHANGE int isPrime[] = { 0, // this is [0] 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, // elements [2], [3], [5], [7] are true because 2, 3, 5 and 7 are primes 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, // elements [12], [14], [15], [16], [18], [20] are false because they are composites 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 };

// Enter your code below

/* last statement of this C program */ return 0; }

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago