Question
in visual studio build a masm program that prints out the prime numbers in a array
L1001-Sieve of Eratosthenes Please use your textbook as a reference. Goal: Use what we have learned to generate prime numbers. Prime numbers have many applications in computer science and as such, efficient ways to discover prime numbers can be very useful. Mathematicians have been intrigued by the concept for ages including the Greek mathematician, Eratosthenes of Cyrene (famous for calculating the circumference o the Earth and probably having a sweet beard). Eratosthenes introduced the following algorithm for discovering small primes. (Fewer than a thousand or so digits can be considered small). Sieve of Eratosthenes 1. Begin with a list of all integers (2-n). 2. Let p-2 3. Count multiples of p (2p, 3p, 4p.) up to n, marking them invalid. Find the next unmarked number from p. Let p that number. If no such number exists, stop. Count again. (Go to step 3). When no more numbers are available, stop. Your unmarked numbers are all prime. 4. s. 6. 7. For example, If you are computing primes 1-13: 1 2 3 4 5 6 7 8 9 10 11 12 13 start 1 23 4 5 6 7 8 9 10 11 12 132 1 2 34 5 67 89 10 11 12 13 3 . 1 2345 6 7 8 9 1 11 12 13 5 2 3 4 5 6 Z 8 9 10 11 12 137 .234 5 6 289 1e 11 12 13 f 11 2 34 5 6 Z89 10 11 12 13 13 00) For your program, create an array of 1 contents of each byte will default to 0, but may be marked to 1. From position 2, set each index with a multiple of 2 to 1. Then do this for 3, 5, etc. Print out the primes (even in color if you like). Submit your resulting program to Blackboard. 0,000+ bytes. Your index will represent the integers, and the
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include<math.h>
#include<vector>
void primes(int n){
vector<int> x(n+1,true);
x[0]=false; // As 0 is not considered as prime no
x[1]=false;// As 1 is not considered as prime no
int m= sqrt(n);
for(int i=2;i<=m;i++){ //start checking from 2 to m
if(x[i]){
for(int j=i*i;j<=n;j++){
x[j]=false;
}
}
}
for(int i=0;i<=n;i++){
if(x[i]) cout << i << ","; //printing all
}
cout << endl;

}
int main(){
primes(100);
return 0;
}

Add a comment
Know the answer?
Add Answer to:
in visual studio build a masm program that prints out the prime numbers in a array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The Sieve of Eratosthenes is a simple, ancient algorithm for finding all prime numbers up to...

    The Sieve of Eratosthenes is a simple, ancient algorithm for finding all prime numbers up to any given limit. It does so by iteratively marking as composite lie., not prime) the multiples of each prime, starting with the multiples of 2 The sieve of Eratosthenes can be expressed in pseudocode, as follows: Input: an integer n Let A be an array of 8oo1ean values, indexed by integers 2 to n, initially all set to true. for t - 2, 3,...

  • Prime Number Programing in C Note: The program is to be written using the bitwise operation....

    Prime Number Programing in C Note: The program is to be written using the bitwise operation. Use an integer array (not a Boolean array) and a bit length (for instance 32 bits). In this program you will write a C program to find all prime numbers less than 10,000. You should use 10,000 bits to correspond to the 10,000 integers under test. You should initially turn all bits on (off) and when a number is found that is not prime,...

  • No. 7 7th question i want this code to be done on c++ visual studio without...

    No. 7 7th question i want this code to be done on c++ visual studio without using bool operation. and please try to make as simple as possible. Also i need flowchart for the code thanks. Q7 I need a code programmed on c++ visual studios. Also flowchart of the code. Try to make it simple college level understandable code. thanks. b. wg. Prompt the user to input the value of a double variabler, which stores the radius of a...

  • A program for generating random numbers on a computer is to be tested. The program is...

    A program for generating random numbers on a computer is to be tested. The program is instructed to generate 100 single-digit integers between 0 and 9. The frequencies of the observed integers were as follows. At the 0.05 level of significance, is there sufficient reason to believe that the integers are not being generated uniformly? Integer 0 1 2 3 4 5 6 7 8 9 Frequency 8 9 7 8 11 12 6 12 13 14 (a) Find the...

  • write a Matlab program ( solve the three questions). please use array and create your own...

    write a Matlab program ( solve the three questions). please use array and create your own function to check primality Question 1 : [10 points) Write a MATLAB program that will store all the first 1000 prime numbers in an array variable named arr_of_primes. Please note that a prime number is a positive integer that is bigger than or equal to 2 which is divisible only by 1 and itself. Examples of the first 8 primes are: 2, 3, 5,...

  • Write an MPI program, countprimes which will count the number of prime numbers in the numbers...

    Write an MPI program, countprimes which will count the number of prime numbers in the numbers from 1 to n inclusive where n is a long integer. The value for n which can be set in the program using a constant should be 50,000. Each process will test its share of the cases. Each process should print out any primes that it finds in a readable manner indicating which process found it and the actual prime. The master process should...

  • Write a program that finds and output all of the prime numbers between 2 to 2000...

    Write a program that finds and output all of the prime numbers between 2 to 2000 to the display screen. You are to declare any required array in main and pass them to your function sieve that will process the array.C++

  • One way to find prime numbers less than n is to treat them as array indices....

    One way to find prime numbers less than n is to treat them as array indices. Mark each position as True initially, assuming that all numbers are prime. Then, starting with index 2, mark all multiples of 2 (greater than 2) as not prime (False). Repeat this for multiples of 3, then multples of 4, etc. When the algorithm terminates, only prime indices will still be True; everything else will be False. The following function takes an integer n as...

  • The task involves writing a C++ program that determines the prime numbers between 1 and 100....

    The task involves writing a C++ program that determines the prime numbers between 1 and 100. The steps you should follow to identify the prime numbers are the following. 1. The number 1 is not a prime number, so it should be scratched. 2. Starting from the first prime number, which is 2, you scratch all the numbers that are the multiple of 2. You should not scratch out 2 itself. 3. The next number in the sequence after the...

  • PLease IN C not in C++ or JAVA, Lab3. Write a computer program in C which...

    PLease IN C not in C++ or JAVA, Lab3. Write a computer program in C which will simulate a calculator. Your calculator needs to support the five basic operations (addition, subtraction, multiplication, division and modulus) plus primality testing (natural number is prime if it has no non-trivial divisors). : Rewrite your lab 3 calculator program using functions. Each mathematical operation in the menu should be represented by a separate function. In addition to all operations your calculator had to support...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT