Reference no: EM132103239
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.
Identify and classify the information contained
: Based on the potential for misuse or embarrassment, what information would be confidential, sensitive but unclassified, or for public release?
|
Write ruby function prime
: (2) Using prime? (n) write Ruby function primearray(n) that returns an array that contains all prime numbers that are less than n.
|
What tactics she can use to get a higher ranking
: She also wants to know if she should start a paid ad campaign on Google too. What advice would you give her?
|
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.
|