Skip to main content

Prime Numbers

Prime Number is a natural number greater than 1 that has exactly two distinct natural number divisors: 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number.
For example, 13 can only be divided by 1 and  by 13 itself.
Here is a list of all the prime numbers up to 100:
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,..
1 is not a prime number as in definition “For a number to be prime it must have two distinct (different) factors.
Algorithm
Step1: Input the number(n) to check for prime number
Step2: If n is below or equal to 1  then go to step 12
Step3: if n is equal to 2 then go to step 11
Step4: Assign variable count =n / 2
Step5: Assign variable a=1
Step6: Add 1 to a and store it to variable a
Step7: remainder = n % a
Step8: if remainder=0 then go to step 12
Step9: subtract one from count and store it to variable count
Step10: if count is not equal to 0 then go to step 6
Step11: Display “it is a prime number”: go to step 13
Step12: Display “it is not a prime number”
Step13: Stop

In the first step we will read the number(n) inputted by user to check for prime number.
In the next step, we will check if the number(n) is below or equal to 1 if its true then that number cannot be a prime number
In third step, we will check if number(n) is equal to 2 if its true then it is prime number.

As now the number is greater than 2 , we will find if number(n) is divisible by any other number than itself and 1. If its divisible by any number then its not a prime number otherwise it’s a prime number.
We will use the modulus operator to find out the remainder and check if remainder is 0 or not, if the remainder is 0 then its not a prime number.
The modulus, or remainder, operator divides number1 by number2 and returns only the remainder. The sign of the result is the same as the sign of number1. The modulus operator is represented as mod or %



To see the working of Prime Number Algorithm 
Click here to watch on YouTube






To see the working of Prime Number Flowchart ,







Learn to write the program in C to find out whether a given number is prime or not, Click here to watch on YouTube







Learn how to make Prime Number App in MIT App Inventor, Click here to watch on YouTube




To Download the Prime Number Android App, Click Below

Comments

Popular posts from this blog

Fibonacci Sequence Flowchart

Fibonacci Sequence Flowchart In the previous video of Fibonacci sequence ,we learned about the Fibonacci series and how to write an algorithm. In this video we will learn how to draw a flowchart for it. First let us write an algorithm for it again. 0,1,1,2,3,5,8,13,21,34,55,89,… Step1: Input the number(n) till which the Fibonacci series will run Step2: Assign the variables a equal to -1 and b equal to 1 Step3: Add the variables a & b and assign it to variable x Step4: Display the value of x Step5: Assign the value of b to variable a Step6: Assign the value of x to variable b Step7: Subtract one from n and store it to variable n Step8: If the value of n is not zero, go back to the Step3 Step9: Fibonacci numbers displayed till n numbers. To see the working of above flowchart,  Click here to Watch on YouTube To write the program in C,   Click here to Watch on YouTube To make the Fibonacci Sequence  Android App in MI

Factorial of a Number

       FACTORIAL   !   The factorial of a positive integer n , denoted by n! , is the product of all positive integers less than or equal to 1.     For example the factorial of 6 is 6! = 6*5*4*3*2*1 = 720 The value of 0! is 1 , according to the convention for an empty product. We can calculate a factorial of a number(n)  from the previous one i.e. by multiplying the number (n)  to a factorial of number(n-1) . n! = n * (n-1)! For example: 5! = 5*4*3*2*1 = 120 . So calculate the factorial of 6 by above rule. 6! = 6 * (6-1)! = 6 * 5!= 6 * 120 = 720 7! = 7 * (7-1)! = 7 * 6!= 7 * 720 = 5040 To see the working of flowchart,  Click here to watch on YouTube To write the program in C,  Click here to watch on YouTube To Create the Factorial App in MIT App Inventor  Click here to watch on YouTube Download the Factorial Android App here Factorial Android App