Loading
View RSS Feed

Angad Kumar Shukla's blog

How To Write A Shell Script To Print The Immediate Prime Numbers Before And After A Given Number?

Rating: 76 votes, 4.89 average.
Here is a Shell script for finding out The Immediate Prime Numbers Before And After A Given Number.

Code:
echo "enter the value:" 
read x 
for((j=2;$j < $x;j++)) 
do 
c=0 
for((i=2;$i <= $j;i++)) 
do 
z=`expr $j % $i` 
if [ $z -eq 0 ] 
then 
c=`expr $c + 1` 
fi 
done 
if [ $c -eq 1 ] 
then 
max=$j 
fi 
done 
echo "lower prime is:->" 
echo $max 
y=0 
x=`expr $x + 1` 
while [ $y -eq 0 ] 
do 
c=0 
for((i=2;$i <= $x;i++)) 
do 
z=`expr $x % $i` 
if [ $z -eq 0 ] 
then 
c=`expr $c + 1` 
fi 
done 
if [ $c -eq 1 ]

Submit "How To Write A  Shell Script To Print The Immediate Prime Numbers Before And  After A Given Number?" to Digg Submit "How To Write A  Shell Script To Print The Immediate Prime Numbers Before And  After A Given Number?" to del.icio.us Submit "How To Write A  Shell Script To Print The Immediate Prime Numbers Before And  After A Given Number?" to StumbleUpon Submit "How To Write A  Shell Script To Print The Immediate Prime Numbers Before And  After A Given Number?" to Google

Updated 02-10-2011 at 06:33 PM by Harsh

Categories
Unix

Comments

  1. santu.5200's Avatar
    :rockon: :rockon: :rockon:
  2. angad's Avatar
    i hope this code worked for u
  3. prafic's Avatar
    angad can u add some more shell script programs..............
  4. sachdev's Avatar
    we are waiting for more programs sir
  5. fempo's Avatar
    Hmmmm...

    The code seems to miss something?
  6. kushalsheth's Avatar
    :clap2:
    hey angad ,give me solution of follow

    1. Write a shell script to print the file names of all files having .txt extension of a given directory after converting to uppercase letters. The input (directory name) should be given as command line argument. The script will also check whether sufficient arguments are passed or not and whether the argument is a directory or not. In case of invalid input, proper message should be displayed.

    2. Write a script that would print any one of the following message along with the username according to the system time:
    Good Morning, between 12 AM and 12 PM.
    Good Afternoon, between 12PM and 4 PM
    Good Evening, after 4 PM

    3. Write a shell script – compare.sh
    It will take two string arguments from the user, compare them and give the output “Both are same” or “Both are different” based on whether they are same or not. If input string is null, error message should be given.
    If user enters less or more number of arguments, an error should be thrown

    4. Write a script which accept a number from command line and check whether it is prime or not. If it is prime number then store this number into prime.txt file otherwise store into notprime.txt file.
    If user enters less or more number of arguments, an error should be thrown.

    5. Write a shell script – reverse.sh
    It will take a line as argument from the user, and display it in reverse order. If input string is null, error message should be given.
    If user enters less or more number of arguments, an error should be thrown

    Ex :
    Input : This is Unix.
    Output : Unix is This.

    6. Write a shell script that prints the total number of users having a given file in their home directory. The input filename should be supplied as command line argument.

    7. Write a shell script to count the frequency of semi colons(;) in a given file. The input file should be given as command line argument. The script will check whether sufficient arguments are there or not and whether the argument is a file or not while the script is executed. In case of invalid input , proper message should be displayed.

    8. Use awk for displaying first n numbers in Fibonacci series where n is supplied as command line argument.
    Note: Fibonacci series of numbers are 0 and 1, and each remaining number is the sum of the previous two. For e.g. first 5 numbers in Fibonacci series are 0, 1, 1, 2, 3

    9. Write a shell script to display the four letter words in a given file. The script will also print the count of such words. The input file should be given as command line argument. The script will check whether sufficient arguments are there or not and whether the argument is a file or not while the script is executed. In case of invalid input, proper message should be displayed.
    NOTE: The output should display the word only once although it may occur in the file more than once. Total count should be also the count of the distinct words.

    e.g If the content of the given file is as folows----------------
    There are three bags.
    This is a blue bag.
    My blue bags are full.

    The output should be as----------------------
    bags
    This
    blue
    full
    Count of four letter words is: 4

    10. Write a shell script to display the longest line in a given file. It will also display the number of words in that line. The input file should be given as command line argument. The script will check whether sufficient arguments are there or not and whether the argument is a file or not while the script is executed. In case of invalid input, proper message should be displayed.
  7. Unregistered's Avatar
    dluplaziiweqib,<a href="http://scarpeoutlet.tumblr.com/">hogan online</a>,qjbiogn vnewlqu,<a href="http://borseoutletonline.tumblr.com/">louis vuitton</a>,bpmhfsr vzlxezp,<a href="http://stivaliitaliaoutlet.tumblr.com/">ugg australia</a>,cthexsf jkwxbbo,<a href="http://piuminioutletonline.tumblr.com/">spaccio moncler</a> qtiywpq qruiqni,<a href="http://spacciobolognaoutlet.tumblr.com/">woolrich parka</a>,xolbwqkkylwcdq.
  8. Unregistered's Avatar
    Â*Gekämpft, um zu leben, verloren verrĂĽckt , um die schöne junge Leben spielen Art von Geschmack .
    <a href="http://www.letourdumonde.ch/moncler/Index.asp?id=16">moncler</a>
    <a href="http://www.kunstszeneschwyz.ch/jackenoutlet/Index.asp?id=30">moncler</a>
    <a href="http://www.kunstszeneschwyz.ch/ugg/Index.asp?id=7">ugg</a>
    <a href="http://www.letourdumonde.ch/bootsschweiz/Index.asp?id=43">ugg schweiz</a>
    http://www.letourdumonde.ch/bootssch...ndex.asp?id=49
    http://www.letourdumonde.ch/bootsschweiz/Index.asp?id=1
    http://www.kunstszeneschwyz.ch/jacke...ndex.asp?id=35
    http://www.letourdumonde.ch/bootssch...ndex.asp?id=31
    http://www.kunstszeneschwyz.ch/ugg/Index.asp?id=25
  9. Unregistered's Avatar
  10. Unregistered's Avatar
    http://www.residencefleming.it/scarpe-hogan/
    http://www.excicom.fr/doudoune-moncler/
    http://www.autolooking.fr/moncler-pas-cher/
    http://www.inforganiclabs.com/parajumpers-jakke/28.html
    parajumpers blogg
    parajumpers bergen

    http://www.scelgoiosassomarconi.it/hogan-outlet/
    Moncler Piumini Outlet
    http://www.residencefleming.it/piumini-moncler/
    http://www.excicom.fr/canada-goose-pas-cher/
    http://www.taylorstakeoneverything.c...-norge/24.html
    parajumpers jacket
    http://www.taylorstakeoneverything.c...-norge/12.html

    http://www.esmra.com/by-dre-studio/20.html
    http://www.esmra.com/by-dre-studio/5.html
    beats by dre monster
    beats by dre pris
    http://www.esmra.com/by-dre-studio/22.html

    http://www.autolooking.fr/ugg-pas-cher/
    http://www.inforganiclabs.com/canada...-norge/26.html
    canada goose kensington parka
    http://www.inforganiclabs.com/canada...-norge/33.html

    http://www.esmra.com/canada-goose-jakke/36.html
    http://www.esmra.com/canada-goose-jakke/29.html
    http://www.esmra.com/canada-goose-jakke/42.html
    canada goose chilliwack
    http://www.esmra.com/canada-goose-jakke/32.html

    http://www.acgeraci.it/ugg-italia/
    http://www.taylorstakeoneverything.c...-parka/21.html
    http://www.taylorstakeoneverything.c...-parka/13.html
    canada goose kensington parka

    http://www.galerieslafay.fr/bottes-ugg/
    Ugg Outlet Italia Online
    http://www.galerieslafay.fr/doudoune-canada-goose/
    http://www.taylorstakeoneverything.c...-vesker/8.html
    http://www.taylorstakeoneverything.c...vesker/28.html
    mulberry antony bag


    pjabpnsosuuu
    jwqgdymowwlh
    avtoyhasewdf
    mfkwogmbpqpz
    xvphcistlbgj
    hrbcntrmpwbf
    npghrbhimjsi
    xvedoyohbgsu
    kepztfjpbxjh
    khbdocnhofrq
  11. Unregistered's Avatar
  12. #cennick[CMSVSCSPRFFV]'s Avatar
    Weaving [URL=http://www.promdressessales.co.uk/events-styles/quinceanera-dresses.html]Cheap Quinceanera Dresses UK[/URL] con soda straws can be [URL=http://www.dressesonlineshops.co.uk/wedding-dresses/princess-wedding-dresses-1.html]http://www.dressesonlineshops.co.uk/wedding-dresses/princess-wedding-dresses-1.html[/URL] loose so i recommend that adults and young prom dresses with more advanced skills use coffee straws.Color refers to the absence or presence of color in white diamonds.
    Then you need make them interested enough to read your cover letter.Supervisors need to have the [URL=http://www.dressesonlinesales.co.uk/womens-dresses/wedding-party-dresses/bridesmaid-dresses.html]Bridesmaid Dresses UK[/URL] potency to identify the problems that stand on the way to their mission.
    As caffeine is a diuretic, so drinking it means you lose more prom party dresses dresses than you should-So it's not going to hydrate you as much, either.Components of prom dresses electromagnetic locksanother name for an electromagnetic lock is a mag lock it is composed of an electromagnet and an armature wedding dresses plate.
    Useful herbal treatmentsmany herbal treatments have historically been used in treating irritant contact dermatitis, although few herbs have been subjected to long-Term contemporary scientific research studies to validate the beneficial health prom dresses patients have been reporting for decades.For instance, how the [URL=http://promptprocessservice.com]Promptprocessservice[/URL] homecoming dresses's orbit around the sun has been stable for thousands or even billions of years so as to sustain life and that this [URL=http://www.dresspurty.com/wedding-dresses/formal-wedding-dresses/plus-size-wedding-dresses.html]http://www.dresspurty.com/wedding-dresses/formal-wedding-dresses/plus-size-wedding-dresses.html[/URL] perfect orbit occurred without any guidance of any kind.



Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.