How to tell Fortran to get rid of composite numbers?

In summary, the problem is to implement the sieve of Eratosthenes in fortran 90 to find all primes between 2 and 100. The suggested method is to use a loop to eliminate multiples of each number starting from 2, but the question remains on how to indicate whether a number is prime or composite. Instead of a specific equation, an algorithm is needed to determine if a given number is prime or composite. This can be achieved by choosing a suitable data type to store information about the numbers.
  • #1
Sir Arun
2
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
  • #2
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?
 
  • #3
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?
 

1. How do I identify composite numbers in Fortran?

To identify composite numbers in Fortran, you can use the built-in function MOD, which calculates the remainder when one number is divided by another. If the remainder is equal to 0, then the number is composite. You can also use a loop to check if the number is divisible by any number other than 1 and itself.

2. Can I use a built-in function to get rid of composite numbers in Fortran?

Fortran does not have a built-in function specifically for getting rid of composite numbers. However, you can use the MOD function or write your own algorithm to check for and eliminate composite numbers from a list of numbers.

3. How can I efficiently get rid of composite numbers in a large data set using Fortran?

To efficiently get rid of composite numbers in a large data set, you can use the Sieve of Eratosthenes algorithm. This algorithm involves creating a list of numbers and systematically crossing out all the composite numbers until only the prime numbers are left. This method is more efficient than checking each number individually.

4. Is there a Fortran library or module for dealing with composite numbers?

There is no specific library or module for dealing with composite numbers in Fortran. However, there are libraries and modules available for prime number generation and manipulation, which can be useful in identifying and eliminating composite numbers.

5. How can I test if my Fortran code successfully gets rid of composite numbers?

You can test your Fortran code for getting rid of composite numbers by providing a set of numbers and manually checking if the output contains only prime numbers. You can also use test cases with known answers to verify the correctness of your code.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
814
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
6K
  • Programming and Computer Science
Replies
8
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
9K
Replies
1
Views
950
  • Engineering and Comp Sci Homework Help
Replies
2
Views
8K
Back
Top