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
Corrected Exercise #1: 1. Explain the following unexpected result: why did you get the system date command instead of the script? $ whereis date date: /bin/date ... $ echo $PATH

how to rewrite C++ program the DNAStrand class (DNA Project) to instead store the nucleotide sequence in a dynamically-allocated array?

Architecture and Components The .NET Framework 3.5 The .NET Structure (pronounced dot net) is an application framework that works generally on Enthusiasm Microsoft windows. It has

Write a Program to Show Twenty Ellipses 1. Write a program to show twenty ellipses which move away from the mouse pointer. Their initial locations should be random.

Board Coloring Problem Description In this problem you are given a board in which some of the elements are placed as shown in diagram below. Each element represents a color.

Produce a hierarchy chart, a structured flowchart, and a Pascal program (with appropriate comments) to generate the Sales Commission Report shown below. The commission for each sal

Define an Example of Switch Statement? estimate(number) int number; /* Estimate a number as none, one, two, several, many */ {       switch(number) { case 0 :

EF308 Assignment 2 Due: 3pm, 26 April 2012 Introduction This assignment is loosely based on Cheung et al. (2005) and Molodtsova and Papell (2009) and examines the out-of- sample pr

Lennie McPherson, proprietor of Lennie''s Bail Bonds, needs to calculate the amount due for setting the bail. Lennie requires something of value as collateral, and his fee is 10%

Problem Solving 1. Write Pascal code that accepts as input the names of the students, course work score and exam score for a unspecified number of students who have taken a subjec