Showing posts with label shell progrmming. Show all posts
Showing posts with label shell progrmming. Show all posts

Friday, 3 April 2015

shell script to print prime numbers upto a given Range

shell script to print prime numbers upto a given Range


clear
echo enter a range
read range
echo 2
j=3
while test $j -le $range
do
i=2
x=`expr $j - 1`
while test $i -le $x
do
if [ `expr $j % $i` -ne 0 ]
then
i=`expr $i + 1`
else
break
fi
done
if [ $i -eq $j ]
then
echo $j
fi
j=`expr $j + 1`
done



Thursday, 2 April 2015

write a shell script to check the given number is armstrong or not

write a shell script to check the given number is armstrong or not
clear
echo enter any number to check armstrong or not
read n
m=$n
sum=0
while [ $m != 0 ]
do
        y=`expr $m % 10`
        x=`expr $y \* $y \* $y`
        sum=`expr $sum + $x`
        m=`expr $m / 10`
done
if [ $sum -eq $n ]
then
        echo the given number is armstrong
else
        echo the given number is not armstrong
fi


output





write a shell script program to generate multiplication table

write a shell script program to generate multiplication table


clear
  echo "which number to generate multiplication table"
  read number
  i=1
  while [ $i -le 10 ]
  do
  echo " $number * $i =`expr $number \* $i ` "
  i=`expr $i + 1`
  done





output




Friday, 27 March 2015

Shell Script to Find Factorial of a Number

3)write a Shell Script to Find Factorial of a Number?
clear
echo "enter number"
read fact

ans=1
counter=0
while [ $fact -ne $counter ]
do
counter=`expr $counter + 1`
ans=`expr $ans \* $counter`
done
echo "Total of factorial is $ans"

Write a shell program to check whether a given string is palindrome or not


2) Write a shell program to check whether a given number is palindrome or not?
clear
echo "Enter the number you want?"
read num
m=$num
rev=0
while [ $num -gt 0 ]
do
r=`expr $num % 10`
rev=`expr $rev \* 10 + $r`
num=`expr $num / 10`
done
if [ $m = $rev ]
then
echo " $m is Palindrome"
else
echo " $m is not Palindrome"
fi