Peacefull Uses of Nuclear Energy

Topics: Prime number, Mathematics, Summation Pages: 14 (1221 words) Published: May 12, 2013
// Biggest of three numbers

echo "Enter three numbers "
if [ \$a -gt \$b -a \$a -gt \$c ]
then
echo " A is big "
elif [ \$b -gt \$c ]
then
echo " B is big "
else
echo " C is big "
fi

OUTPUT

[1csea56@local host~]\$ sh biggest.sh

3 4 9

C is big

[1csea56@local host~]\$ sh biggest.sh

7 5 2

A is big

RESULT:

Thus a program has been written in the UNIX successfully to find the biggest of three numbers and the output is verified.

//FIBONACCI SERIES

echo "enter the number"
f=0
a=0
b=1
i=0
while [ \$i -le \$n ]
do
f=`expr \$a + \$f`
a=`expr \$b`
b=`expr \$f`
i=`expr \$i + 1`
echo \$f
done

OUTPUT

[1csea56@local host~]\$ sh fib.sh

Enter the number
5
0
1
1
2
3

RESULT

Thus a program to perform Fibonacci series was written and executed successfully.

// FACTORIAL OF A NUMBER

echo "Enter the value”
i=1
f=1
while [ \$i -le \$n ]
do
f=`expr \$f \* \$i`
i=`expr \$i + 1`
done
echo "Factorial Of \$n is:\$f"

OUTPUT

[1csea56@local host~]\$ sh factorial.sh

Enter the number
4

Factorial of 4 is: 24

RESULT
Thus a program to find factorial of a number was written and executed successfully.

// Palindrome program

len=0
i=1
echo “enter the string”
len=`echo \$str|wc -c`
len=`expr \$len - 1`
halflen = `expr \$len/2`
while [ \$i –le \$halflen ]
do
c1= `echo \$str|cut -c \$i`
c2= `echo \$str|cut -c \$len`
if [ \$c1! = \$c2 ]
then
echo “ string not palindrome”
exit
fi
i=`expr \$i +1`
len = `expr \$len -1`
done
echo “string is palindrome”

OUTPUT

[1csea56@local host~]\$ sh palindrome.sh

Enter the String

malayalam

string is palindrome

[1csea56@local host~]\$ sh palindrome.sh

Enter the String

string is not palindrome

RESULT:
Thus a program has been written in the UNIX successfully to find the Palindrome of a string and the output is verified.

//PROGRAM TO PERFORM ARITHMETIC OPERATIONS

echo "enter the numbers"
2.sub
3.mul
4.div
5.exit\n"
case \$op in
1)
c= `expr \$a + \$b`
;;
2)
c=` expr \$a - \$b`
;;
3)
c= `expr \$a \* \$b`
;;
4)
c= `expr \$a / \$b`
;;
5)
exit
;;
esac
echo \$c

OUTPUT

[1csea56@local host~]\$ sh arithemetic.sh

Enter the numbers
1 2
2.sub
3.mul
4.div
5.exit
1
3

[1csea56@local host~]\$ sh arithemetic.sh
Enter the numbers
1 2
2.sub
3.mul
4.div
5.exit
2
-1

RESULT

Thus a program has been written successfully in the UNIX to perform the arithmetic operations and the output has been verified

// CHECKING A NUMBER FOR ODD OR EVEN

echo "Enter a number"
z=`expr \$a % 2`
if test \$z -eq 0
then
echo "Even number"
else
echo "Odd number"
fi

OUTPUT

[1csea56@local host~]\$ sh oddoreven.sh
Enter a number
2
Even number

[1csea56@local host~]\$ sh oddoreven.sh
Enter a number
5
Odd number

RESULT:

Thus the program is written and executed for checking the given number is even or odd.

//SUM OF DIGITS OF A NUMBER

echo "Enter the number"
c=0
a=0
while [ \$x -ne 0 ]
do
c=` expr \$x \% 10 `
a=` expr \$a \+ \$c `
x=` expr \$x \/ 10 `
done
echo "Sum of digits is \$a"...