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

  Implement a mips asm program that requests for three numbers

Implement a MIPS asm program that requests for three numbers from the user. Month, Day, and Year. You may assume that a valid date is given.

  An asynchronous sequential logic circuit is given on page

an asynchronous sequential logic circuit is given on page by its primitive flow map i.e. initial state table where x1

  Determine the best match for a token

COMP90049 Knowledge Technologies Project: Lexical Normalisation of Twitter Data. Determine the best match(es) for a token with respect to a reference collection

  Determine which type of cache memory is the most efficient

Determine which type of cache memory is the most efficient, and provide one example that depicts the manner in which the use of one type of cache memory makes your computer processing more efficient than another.

  What is the purpose of the border-collapse property

What is the purpose of the border-collapse property? What layout information does a tag by itself indicate to the browser?

  List two features of the asynchronous connection

List two features of the asynchronous connection that allow the receiver to stay in sync with the incoming data stream.

  Analyze why getty image embraced agile methodologies

Analyze why Getty Image embraced Agile methodologies. Speculate on the result if Agile methodologies were not embraced in this situation.

  Explain how is the process that you followed similar to or

describe the steps you have taken to maintain and redesign your site over the past several weeks. how is the process

  Questionfollowing narrative summarizes an interview with an

questionfollowing narrative summarizes an interview with an accounts clerk working for eyetunes club. members of club

  Explain the situation in terms of pci compliance standard

On your exit, a store employee asks to give your receipt and checks all the contents of the store bag. Document each of the above described events that are described and explain them in terms of PCI compliance standard.

  Write a paper on group policies

Group Policies: Write a 3 paragraph paper on Group policies. Explain what they are, how they can be used, and what their strenghts and weaknesses are.

  Draw a domain model diagram for the description

Draw a domain model diagram for the description above. Make sure to show attributes, association names, multiplicities - designs from the above Library

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