shell script to check that a given number is prime or not, Programming Languages

 W.A.S.S to check that whether a given number is prime or not.

 Program

 

# W.A.S.S to check that whether a given number is prime or not.

 echo -e " enter  number \c"

read number

i=2

flag=0

 

while test $i -lt $number                            #starts from 2 to number-1

do

    if test `expr $number % $i` = 0            #if the no is completely divisible by i

    then

           flag=1

           break

    fi

    i=`expr $i + 1`

done

 

if test $flag = 0

then

    echo "Number is prime"

else

    echo "Number is not prime"

fi

 

Output

enter  number 55

Number is not prime

 

enter  number 13

Number is prime

 

enter  number 21

Number is not prime

 

Posted Date: 9/26/2012 4:27:33 AM | Location : United States







Related Discussions:- shell script to check that a given number is prime or not, Assignment Help, Ask Question on shell script to check that a given number is prime or not, Get Answer, Expert's Help, shell script to check that a given number is prime or not Discussions

Write discussion on shell script to check that a given number is prime or not
Your posts are moderated
Related Questions
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4


Implement a two-dimensional table in Prolog. Your program will contain: 1.  An insert_entry predicate that takes a table, row, column and an entry and inserts the entry at the g

How to read datasets in multiple text files in an non interactive program?

Write an assembly program that computes Fibonacci numbers 2-5. a. Assume Fib(0)=0 and Fib(1)=1. b. Store Fib(2) in EAX, Fib(3) in EBX, Fib(4) in ECX and Fib(5) in EDX. c. Use a LOO

Write a pseudocode for a program that reads a temperature as a whole number from a user and outputs a “probable” season (winter, sprint, summer, or fall) depending on the temperatu

There actually isn't all that much to this section. All we are going to do now is work a quick illustration using Laplace transforms for a 3 rd order differential equation therefo

#questiWrite down different system calls for performing different kinds of tasks.on..

Consider the operation of a line of supermarket checkouts and the profiles of customers and their shopping baskets. Use a random number generator to create the data for these profi

Write a function called threshold1 (in a file called 'threshold1.m'. The function takes three arguments. The first two are arbitrarily sized arrays, A and B, and the third is a pos