Question 5

Check a given number is prime or not

Prime number: A number which is divisible by 1 and by itself.

Note: 1 is not a prime number. Prime number starts with ‘2’

Algorithm:

#1 Get the input number

#2 Initialize the loop variable by 2 and continue till the square root of the number

#3 If the input number is exactly divisible by loop variable then its not a prime number, hence break the loop

#4 Else the given number is prime

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s