1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Helen [10]
3 years ago
11

Create a program that will output the sum of the prime numbers ( 2 - 100). A prime number is a number greater than 1 that cannot

be formed by multiplying two smaller natural numbers. some prime numbers are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37... Example: Find the total sum of prime numbers from 1 - 100 The total sum is 1060. Verify your answers.
Computers and Technology
1 answer:
ruslelena [56]3 years ago
3 0

Answer:

The attached file is a C program that does much of what you want.  It does not output the the sum of the primes, but lists the primes.  The output is simple enough to change.  This program builds quite easily with GCC.

I don't know what language you're using, so I'm just providing a piece of code I've written that might help you out.

Also:

There are a few tricks in searching for prime numbers.  Here are some that I always like to take into account.

1) With the exception of 2 and 3, all primes are one away from a multiple of six

2) When testing a number for divisibility, you only have to test up as far as its square root.

3) You don't need to test for divisibility by composite numbers.  Only prime factors are needed. Any composite numbers smaller than x will be multiples of primes smaller than x.

So you can very rapidly find primes with a loop that starts at 6, and goes up to whatever limit you want, incrementing by 6. Let's call the number of  that loop x. You then only have to test if the x - 1 is prime and if x + 1 is prime.  That eliminates 2/3 of the iterations needed. Also, when you find primes, put them in an array.  I would start by creating an array with the numbers 2 and 3 already in it (those being the only two primes that are not adjacent to a multiple of six). Then each number tested only needs to be checked for divisibility by numbers in that array that are less than or equal to the square root of the number being tested.  If the number is composite, then it is only divisible by something larger than its square root if it is also divisible by something smaller than its square root.

With all of this big blurb written, and some hard-to-read C code attached, if you're just looking to write something quick to do your homework, and don't care about it being efficient, you can just do something like this javascript style example:

var n, tally = 0, list = [], isPrime;

for(n = 2; n < 100; n++){

 isPrime = 1;

 for(m = 0; m < list.length && list[m] <= Math.sqrt(n) && isPrime; m++){

   if(n % list[m] == 0) isPrime = 0;

 }

 if(isPrime){

   list[list.length] = n;

   tally += n;

 }

}

console.log('sum of primes: ' + tally);

I haven't run that code, so do watch out for any errors I missed.  Good luck!

Download txt
You might be interested in
A network technician is setting up a web server for a small company. The company has obtained a domain name, company-a, from a d
Alja [10]

Answer:

There is Name resolution failure

Explanation:

This normally occurs when the computer can't access the host (your server). It can be caused by several factors, such as:

-Internet connectivity is down

-The client does not have DNS servers configured or is configured with the incorrect DNS server IP addresses.

-The DNS servers are failing.

3 0
4 years ago
A set of blocks contains blocks of heights 1,2, and 4 centimeters. Imagine constructing towers of piling blocks of different hei
SashulF [63]

Answer:

In studies about new medicines, researchers usually give one group of patients the medicine that is designed to treat an illness. They give another group of patients a placebo, which is taken the same way as the medicine but does not actually contain the ingredients of any medicine. Different medicines are tested in different experiments, but the placebos usually contain the same non-medical ingredients. If both groups of patients are healed, then researchers cannot be sure whether the medicine caused improvement, but if the group given the medicine is healed while the group given the placebo remains ill, researchers can conclude that the medicine causes the illness to go away.

In medical experiments, which group receives placebos?

the experimental group

the control group

both the experimental and control groups

neither the experimental nor control group

Explanation:

5 0
3 years ago
What features do you think that a smart fridge should have? Please give me a quick answer! And in detail.
Lina20 [59]
A smart fridge should have a variety of functions. The most important function of a smart fridge and the main incentive to purchase one is the ability to see the food in your fridge at a glance. This refrigerator should be programmed to recognize barcodes and keep track of the stock of certain items. Also, there should be other feature such as the ability to see calendars, create grocery lists, have it read recipes out loud, and more. A feature that should be added is more software protection to defend against hackers, and overall optimization to reduce the price.
7 0
3 years ago
Match the function to its purpose.
schepotkina [342]

Answer:

  • Median :Calculates the average of the two  numbers in the middle of a set of even count of numbers.
  • Mode : This function shows the most frequently  occurring number in a set of numbers
  • Standard deviation : You can see how far each number  varies, on average, from the average  value of the list
  • Rank : With this function, you can determine  the position of a number in an  unarranged array or set.

Explanation:

8 0
4 years ago
According to the word entry, how many definitions are there for the word syllable
Anarel [89]
: a unit of spoken language that is next bigger than a speech sound and consists of one or more vowel sounds alone or of a syllabic consonant alone or of either with one or more consonant sounds preceding or following

2: one or more letters (such as syl, la, and ble) in a word (such as syl*la*ble) usually set off from the rest of the word by a centered dot or a hyphen and roughly corresponding to the syllables of spoken language and treated as helps to pronunciation or as guides to placing hyphens at the end of a line

3: the smallest conceivable expression or unit of something : JOT

4: SOL-FA SYLLABLES

3 0
3 years ago
Other questions:
  • Do you believe that OOP should be phased out and we should start working on some alternative(s)?
    6·1 answer
  • Which of the following values is an example of a floating point number?
    12·1 answer
  • Open a command prompt on PC1. Issue the command to display the IPv6 settings. Based on the output, would you expect PC1 to be ab
    7·1 answer
  • What standard linux utility is used to install and configure software on centos operating systems?
    8·1 answer
  • Being aware of and understanding why potential buyers on a web site do not complete their purchases requires the expertise of __
    11·2 answers
  • Which of these components is a part of the central processing unit (cpu) of a computer??
    14·1 answer
  • Raj’s computer just crashed and he lost most of his files. What should he do to avoid this problem in the future?
    10·2 answers
  • Which measurement symbol is this?<br>PLS HELP<br>​
    14·1 answer
  • Explain one rule the company must follow when using cookies on its website.
    13·1 answer
  • How do you answer someone's question when they have asked?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!