By through following shell programming you can find out the give number is Armstrong or not. Example 153 is a Armstrong number because 1*1*1+5*5*5+3*3*3=153. so it is satisfied the Armstrong condition. 153 numbers is the Armstrong number. We will done these operation using basic arithmetic operation in Linux and UNIX bash shell programming
Source code bash shell Programming Algorithm
echo "Enter the number"
read n
t=$n
s=0
b=0
c=10
while [ $n -gt $b ]
do
r=`expr $n % $c`
i=`expr $r \* $r \* $r`
s=`expr $s + $i`
n=`expr $n / $c`
done
echo $s
if [ $s -eq $t ]
then
echo "Amstrong number"
else
echo "Not an Armstrong number"
fi
OUTPUT CS1252 Operating Systems lap Calculate ARMSTRONG NUMBER
[redhat35@localhost Rhel5]$ sh amstrong.sh
Enter the number
213
36
Not an Armstrong number
[redhat35@localhost Rhel5]$ sh amstrong.sh
Enter the number
153
153
Armstrong number
Monday, May 17, 2010
Calculate Armstrong Number Bash shell programming in Linux and UNIX shell programming
Subscribe to:
Post Comments (Atom)
Labels
3D-2D Translation
Algorithms
Batch Programming
C language
C world
C++
DBMS
Ebook
Games
JAVA
Java Programs
JNTU MATERIALS
JNTU PREVIOUS QUESTION PAPERS
JNTU SYLLABUS BOOKS
LAB MANUALS
Linux
Mobile softwares
Networking
Online Programs
PC TIPS
Software Diagrams
Software Engineering
Softwares
System Software
Visual Basic
0 comments:
Post a Comment