How to tell Fortran to get rid of composite numbers?

Click For Summary
SUMMARY

The discussion focuses on implementing the Sieve of Eratosthenes algorithm in Fortran 90 to identify prime numbers between 2 and 100. The user, Sir Arun, seeks guidance on how to eliminate composite numbers by marking multiples of each prime number. The conversation emphasizes the need for an efficient data structure to store prime status for numbers, suggesting that a simple array can be utilized to track whether each number is prime or not. The key takeaway is that an algorithmic approach is essential rather than relying on a specific formula.

PREREQUISITES
  • Understanding of Fortran 90 programming language
  • Familiarity with the Sieve of Eratosthenes algorithm
  • Basic knowledge of arrays and data structures
  • Concept of prime and composite numbers
NEXT STEPS
  • Implement the Sieve of Eratosthenes in Fortran 90
  • Explore array manipulation techniques in Fortran 90
  • Study algorithm optimization for prime number generation
  • Learn about data structures suitable for number classification
USEFUL FOR

Programmers, computer science students, and anyone interested in algorithm development and number theory, particularly those working with Fortran or similar programming languages.

Sir Arun
Messages
2
Reaction score
0
Problem Statement: Do the sieve of Eratosthenes from 2 to 100 and find all the primesSo I'm trying to do the sieve of Eratosthenes in fortran 90 (I'm using Plato IDE)My efforts to solve this/ method to use:

Obviously, I want the program to do a LOOP starting with every whole number from 2 onwards, and then get rid of all multiples of that number before the next LOOP starts with the next number and so on.

But how do I tell fortran that it should take a number and then strike all multiples of it, essentially getting rid of all composite numbers?Relevant equation: THATs the one I am searching for, which is why I need your help.

thanks for any help,
Sir Arun
 
Last edited:
Physics news on Phys.org
You need some way to hold information ("prime"/"not prime") about 100 numbers in such a way that you can easily access any random element of them. Which data type would you choose?
 
Sir Arun said:
Relevant equation: THATs the one I am searching for, which is why I need your help.
You seem to think that there is some magic formula or equation that will be of use here. That's not true.

What you really need is an algorithm, a sequence of steps to be performed.

For a given number between 2 and 100, how would you manually determine that it is either composite or prime?
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
9K
  • · Replies 6 ·
Replies
6
Views
7K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K