Prime numbers are one of the most basic concept of mathematics and are studied in a theory called number theory.
Primes are the numbers that can only be divided by 1 and and the number itself. For example, 11 is a prime number since I'm left with a remainder if I divide 11 by any number other than 11 or 1. 8 is not a prime because I can divide 8 by 2.
Flowchart For Generating 100 Prime Numbers
Algorithm to generate 100 prime numbers
Step 1: Start
Step 2: Declare Variable num, i, flag
Step 3: Intialize num=1,count=0
Step 4: Repeat until count<=100
4.1: Initialize Variable i=1 and flag=0
4.2: Repeat Until i<=num
4.2.1 if(num%i==0), set flag=flag+1
4.2.2 increment i=i+1
4.3 If(flag<=2), Print num, set count=count+1
4.4 increment num=num+1
Step 7: Stop
In the above algorithm,
- We first define a variable num and initialize it to 1 and a variable count=0 and put it in a loop till it reaches 100.
- Then we initialize 2 variables flag to 0 and i to 1.
- We then check if num is divisible by i, which takes up value till it reaches num. If divisible we increment flag by 1. We repeat the above step until num is greater than or equal to i.
- Then, we check whether flag is equal to 2, if yes Print num and increment count by 1
- After that num increments by 1 and the above process continues till count reaches 100