Write your solution using dynamically allocated arrays

Assignment Help Computer Engineering
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.

Reference no: EM132103236

Questions Cloud

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

Reviews

Write a Review

Computer Engineering Questions & Answers

  What would be your recommendation for future improvement

For the last written assignment for this course, I would like to do a little introspection. I would like you to write a 3 page report that addresses.

  Guassian function and digital transmission technique

Prove the following properties of Gaussian function:Explain four benefit and one de-merits of utilizing the digital (rather than the analog) techniques for transmission of the voice-telephone signals.

  Write a program that draws iterations of the snowflake shape

Write a program that draws the iterations of the snowflake shape. Supply a button that, when clicked, produces the next iteration.

  In how many ways can this be done if professor blue refuses

In how many ways can this be done if Professor Blue refuses to chair the discrete mathematics committee?

  Companies still fail in their use of information technology

Why do big companies still fail in their use of information technology? What should they be doing differently.

  Design a class called numdays

Design a class called NumDays. The class's purpose is to store a value that will convert the number of worked hours to a number of days.

  Detail the target market profiles key buying behaviors and

complete a market segmentation of no more than 1400 words for your buyers. be sure to include the followingq1. detail

  Describe the three subsystems which make up a

read the questions below and formulate a brief answer. your response to each question should be at least 2-5 sentences

  Evaluate the coding artifacts in mpeg encoding

Evaluate the coding artifacts (showing up as video noise) in MPEG encoding. Provide the following details: (i) the signal characteristics of video noise (ii) the causes of the video noise, and, (iii) suggest methods to reduce the video noise.

  Would octal or hexadecimal be a better way to refer

Would octal or hexadecimal be a better way to refer to the addresses in a 16-bit processor? Justify your answer.

  Can we use that algorithm as a subroutine to approx

Can we use that algorithm as a subroutine to approximately solve other NP problems in polynomial time?

  How are authentication and authorization alike

How are authentication and authorization alike and how are they different? What is the relationship, if any, between the two?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd