Reference no: EM132103236
Prime Sum C program !! Dynamically allocated memory
Let P(n) denote the sum of the first n prime numbers. For example, P(1) = 2 and P(3) = 10, since the first three prime numbers are 2, 3 and 5, respectively. Write a program to determine the value of the function P(n) for different values of n. The first few prime sums are 2, 5, 10, 17, 28, 41, 58 and 77. Input The first line of the input file contains a single positive integer, t (t = 20000), representing the number of test cases.
The following t lines contain one positive integer n (n = 10000), representing the prime sum to be computed for the case. Output Write out a single integer on a line by itself for each test case, indicating P(n), for the corresponding input value n.
Sample Input
3
1
6
8
Sample Output
2
41
77
Assignment Details
Even though this assignment can be coded with statically allocated arrays, please write your solution using dynamically allocated arrays.
(Your programs should have either malloc/calloc calls, as well as a call to free.)
In order to efficiently generate the first 10000 primes, please use the Sieve of Eratosthenes. From there, just generate each of the prime sums instead of recomputing for each test case.
Calculate the final purchase price after discount
: At the President's Day sale, a customer can bring in a coupon for a 10%, 20% or 30% discount off of total purchases.
|
Determine the value of the function pn for different value
: Write a program to determine the value of the function P(n) for different values of n. The first few prime sums are 2, 5, 10, 17, 28, 41, 58 and 77.
|
What advice would you give her
: Pretend that you are a SEO consultant hired by a new home baker who is planning on selling her products thorough the internet.
|
Write a driver program with a main method
: Write a method named isPrime, which takes an integer as an argument and returns true if the argument is prime or false otherwise.
|
Write your solution using dynamically allocated arrays
: Even though this assignment can be coded with statically allocated arrays, please write your solution using dynamically allocated arrays.
|
How can you print three rows of values on an lcd
: How can you print three rows of values on an LCD using mbed at the same time for example time, date and year.
|
Test your methods within a class and check
: Test your methods within a class and check that they work properly. Use the method prime(int n) in the implementation of the other 2 methods.
|
Create an array of bool values that are true for all prime
: Create an array of bool values that are true for all prime numbers but are false otherwise. Initially set all of the array entries to true.
|
Importance of application of accounting standards
: BUS707 – Applied Business Research - Discuss the limitation of each of articles and how the limitation differ across the four articles, as well as identify
|