Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
KnowledgeHut upGradKnowledgeHut upGradBackend Development Bootcamp
  • Self-Paced
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

Prime Numbers From 1 To 100 in Java: Display 1 to 100 in Java

Updated on 21 October, 2024

45.48K+ views
11 min read

In my experience as a software developer, I’ve found identifying prime numbers to be a fundamental exercise for understanding control structures and loops in Java. Java is a popular and one of the most used languages, and the reason for its sunny day spotlight is providing features like object-oriented programming, platform independency, predefined libraries, etc. This led me to write a program focused on Prime Numbers From 1 To 100 in Java. This exercise is a practical way to get acquainted with Java’s capabilities for solving mathematical problems and serves as a solid foundation for more complex algorithmic challenges.

By tackling the problem of displaying Prime Numbers From 1 To 100 in Java, I have improved my algorithm development and Java programming skills. This article aims to share these insights with professionals looking to enhance their programming abilities. We will explore sections such as Introduction, Java Program, Prime Numbers in Given Input Range, and Conclusion, providing a step-by-step guide to this essential programming task. 

Let’s build a code for printing prime numbers from 1 to 100 and walk through it. Let’s start!

Check out our free courses to get an edge over the competition.

Java Program

Before jumping to the code, we’ll understand the algorithm to check if a number is a prime number or not. At first, we need to loop over all the numbers from 1 to N and maintain a count of numbers that properly divides the given number. If the count is 2 then we can conclude that the given number is a prime, else it is not a prime. Here’s the code to do that.

Check out upGrad’s Java Bootcamp

int n = 5;
int c = 0;
for(int i=1;i<=n;i++)
   if(n%i==0)
       c++;
if(c==2)
    System.out.println(n+" is a prime number");
else
    System.out.println(n+" is not a prime number");

In the above snippet n is the number which is to be checked if it is a prime number or not, c is a variable that stores the count of proper divisors. And we are looping over the range 1 to n and incrementing the count if we found a proper divisor.

And after coming out of the loop, we are checking if the count is 2 i.e.; there are only two proper divisors (1 and itself). If yes concluding it as a prime number, else a non-prime number. Talking about the time complexity of the above code it is a linear one, so it’s an O(n) complexity code.

To print prime numbers from 1 to n in Java, you can write a program that identifies and outputs all prime numbers within that range.

Now that we were asked to print prime numbers from 1 to 100, we need to run this same algorithm for each number between 1 to 100 and store the prime number. And here’s the code to do that.

Check out upGrad’s Advanced Certification in DevOps

ArrayList<Integer> a=new ArrayList<>();
   for(int n=1; n<=100; n++){
   int c = 0;
   for (int i = 1; i <= n; i++)
       if (n % i == 0)
           c++;
   if (c == 2)
       a.add(n);
   else
       continue;
   }
   System.out.println(a);

In the above code, we’ve declared an ArrayList that stores all the prime numbers in the range of 1 to 100. Now we have two for loops first for loop is for looping over all the numbers between 1 to 100 and the second for loop is our previous prime number algorithm. After running the prime number algorithm for each number we are pushing it into ArrayList if it is a prime number.

Check out: Java Developer Salary in India

And after completing the loops we are printing our ArrayList which displays all the prime numbers between 1 to 100. Talking about the time complexity of the above code, we can see that there are two for loops. So it is an O(n²) complexity code.

We have hardcoded the range in the above code, what if we want to print prime numbers from 1 to 100 in Java using for loop given by the user input?

upGrad’s Exclusive Software and Tech Webinar for you –

SAAS Business – What is So Different?

Prime Numbers in Given Input Range

The whole algorithm will be almost similar to the above code, the only difference we make is taking user input for the lower limit and upper limit of the range.

Let’s build the code now!

Scanner sc=new Scanner(System.in);
int lower=sc.nextInt();
int upper=sc.nextInt();
ArrayList<Integer> a=new ArrayList<>();
for(int n=lower; n<=upper; n++){
int c = 0;
for (int i = 1; i <= n; i++)
if (n % i == 0)
c++;
if (c == 2)
a.add(n);
else
continue;
}
System.out.println(a);

In the above code, we are initializing a scanner for reading user input. We’ve declared two variables lower and upper and assigning those variables with user input. What we have to do is print all the prime numbers between the range [lower, upper]. Our previous algorithm does this task and appends all the prime numbers to the ArrayList.

Also Read: Java Project Ideas & Topics

Learn Software Development Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs, or Masters Programs to fast-track your career.

The following section explains how to find prime number between 1 to 100 in Java.

Program Logic:

The key method of the prime number program in Java includes a loop to check and find prime number between 1 to 100 in Java.

The main method calls the method “CheckPrime” to decide whether a number is prime or not in Java. For example, we have to divide an input number, say 15, from values 2 to 15 and check the remainder. But if the remainder is 0, the number is not prime.

Note that no number is divisible by more than half of itself. Hence, we must loop through just numToCheck/2. So, if the input is 15, its half is 7.5, and the loop will repeat through values 2 to 8.

If numToCheck is completely divisible by another number, the output is false, and the loop is broken.

But if numToCheck is prime, the output is true.

In the main method for how to find prime numbers from 1 to 100 in Java, check isPrime is TRUE and add it to primeNumFound String.

Here is the Java program to print prime numbers from 1 to 100.

public class primeNumFoundber {
    public static void main(String[] args) {
        int i;
        int num = 0;
        int maxCheck = 100; // The limit to find prime numbers is up to 100
        boolean isPrime = true;
        //Empty String
        String primeNumFound = "";
        //Start loop#2 to maxCheck
        for (i = 2; i <= maxCheck; i++) {
            isPrime = CheckPrime(i);
            if (isPrime) {
             primeNumFound = primeNumFound + i + " ";
            }
        }
        System.out.println("Prime numbers from 1 to " + maxCheck + ":");
        // It prints prime numbers from 1 to maxCheck
     System.out.println(primeNumFound);
}
    public static boolean CheckPrime(int numToCheck) {
        int remainder;
        for (int i = 2; i <= numToCheck / 2; i++) {
            remainder = numToCheck % i;
            //if remainder gives 0 than numToCheckber is not prime number and breaks loop, else it continues the loop
         if (remainder == 0) {
             return false;
            }
        }
        return true;
}
}

Output:

The output of this Java program to print prime numbers from 1 to 100 would be:

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Find Prime Number using While Loop in Java

  1. In this program of calculating prime no between 1 to 100 in Java, the while loop is available in the constructor. If we instantiate the class, the constructor will be automatically executed.
  2. Read the “n” value through scanner class object sc.Int(). “FindoutPrime class” is introduced in the class Prime as a new FindPrime(n); the constructor of “FindoutPrime” will be performed.

The while loop in Java iterates until i<=num is false. The remainder of the number/i=0 count will be incremented by 1 and “i” value is increased by 1. If the count=2, the code prints, “number is a prime number”.

Find Prime Number using While Loop in Java:

The program to find prime no between 1 to 100 in Java using “While Loop” is as below.

import java.util.Scanner;
class FindoutPrime
{
         FindoutPrime (int num)
         {
         int count=0,i=1;
         while(i<=num)
         {
            if(num%i==0)
            {
              count++;      
            }
         i++;
         }
         if(count==2)
             System.out.println(num+" is a prime number ");
         else
         System.out.println(num+" is not a prime number ");    
         }
}
class Prime
{
         public static void main(String arg[])  
         {
               System.out.println("Enter a number ");
         Scanner sc=new Scanner(System.in);
         int n=sc.Int();
         new FindoutPrime (n);
         }
}

Output:

The output of the above program on how to find prime numbers from 1 to 100 in Java:

Enter a number

83

83 is a prime number

Output

Enter a number

80

80 is not a prime number

You can implement different programming techniques to print prime numbers from 1 to 100 in Java using while loop.

Find Prime Number using Recursion in Java:

Here are the steps to find prime numbers between 1 to 100 in Java using Recursion.

  1. Firstly, read the entered number n.
  2. The Prime class object will be created in the main method. This step calls the method CheckPrimeOrNot (n) with the help of object p.CheckeprimeOrNot(n);

iii. The method CheckPrimeOrNot (int num) will run and call itself as CheckPrimeOrNot (num). It executes until the condition if(i<=num) is false. But if the condition is false, this method returns the count and is assigned to the c variable. If count=2, the code prints “prime number” else, it prints “not a prime number”.

import java.util.Scanner;
class Prime
{      
         static int count=0,i=1;
         int CheckPrimeOrNot (int num)
         {
                     if(i<=num)
                     {
                        if(num%i==0)
                        {
                          count++;            
                        }
                       i++;
                     CheckPrimeOrNot (num);
                     }
         return count;
         }
         public static void main(String arg[])  
         {
               System.out.println("Enter a number ");
         Scanner sc=new Scanner(System.in);
         int n=sc.Int();
         Prime p=new Prime();
         int c=p. CheckPrimeOrNot (n);
         if(c==2)
             System.out.println("prime number ");
         else
             System.out.println("not a prime number ");    
         }
}

Output:

The  output of prime numbers between 1 to 100 in Java.

Enter a number

8

not a prime number

These are the various methods to find the given range of prime numbers 1 to 100 java. You can implement several programming methods to find, or print prime numbers from 1 to 100 in Java using recursion.

Conclusion

The exploration of Prime Numbers From 1 To 100 in Java serves as a foundational exercise for professionals aiming to enhance their proficiency in Java programming. The process of creating a Java program to list numbers from 1 to 100 and then filtering those numbers to find primes demonstrates the combination of logic and mathematics. It highlights the importance of efficiency and optimization in code, especially when dealing with fundamental algorithms like prime number generation. As professionals navigate their careers, revisiting such fundamental exercises can offer fresh insights and refine problem-solving skills. Thus, mastering the art of identifying prime numbers within a specific range in Java is more than just an academic exercise; it is a stepping stone towards achieving greater complexity and sophistication in programming endeavors. 

Check out all trending Java Tutorials in 2024

If you wish to improve your Java skills, you need to get your hands on these java projects. If you’re interested to learn more about Java, full-stack development, check out upGrad & IIIT-B’s Executive PG Program in Full-stack Software Development which is designed for working professionals and offers 500+ hours of rigorous training, 9+ projects, and assignments, IIIT-B Alumni status, practical hands-on capstone projects & job assistance with top firms.

Frequently Asked Questions (FAQs)

1. What are prime numbers?

Prime numbers are positive integers with exactly two distinct factors, 1 and themselves. Primes are what mathematicians call irreducibl and indivisible. Primes are the building blocks of our number system, like how the atoms are the building blocks of the world. The prime numbers are the numbers that are divisible only by one and by itself.

2. What is sieves of Eratosthenes?

The Sieve of Eratosthenes is an ancient Greek algorithm for finding the prime numbers. The algorithm is known for its simplicity and efficiency, in the sense that it is quite fast for its time and yet it yields prime numbers very well. The algorithm works by eliminating all the multiples of each prime from the composite numbers, starting from the multiples of 2 and ending in the multiples of N (N is the last number you want to find the primes for). Eratosthenes was a Greek mathematician and was considered to be the founder of the library of Alexandria in Egypt. He is well known for calculating the circumference of Earth and its diameter.

3. What are data structures and algorithms?

A data structure is a way for storing data so that a computer program can retrieve and modify it. A data structure is a programming language abstraction. It may be an entity in itself or a part of another data entity. It may be data in its own right, or it may be a mechanism for accessing and manipulating other data. A data structure consists of the data definition, data type, content and the operations that can be applied to the content. Algorithms are the step-by-step procedures for solving a computer problem. Each algorithm is a sequence of actions that will lead to a solution to the problem.

4. Are all prime numbers odd?

No, not all prime numbers are odd. The only even prime number is 2. All other prime numbers greater than 2 are odd. Prime numbers are defined as natural numbers greater than 1 that have no positive divisors other than 1 and themselves.

5. Is one a composite?

In mathematics, a composite number is a positive integer that has more than two distinct positive divisors. In other words, it is not a prime number. Examples of composite numbers include 4, 6, 8, and 10.

RELATED PROGRAMS