• Welcome to Bashguru

    Linux is one of popular version of UNIX operating System. It is open source as its source code is freely available. It is free to use. Linux was designed considering UNIX compatibility. It's functionality list is quite similar to that of UNIX and become very popular over the last several years. Our Basic motive is to provide latest information about Linux Operating system.

  • Python Programming

    Python is a comparatively simple programming language, compared to c++. Although some of the benefits of c++ are abstracted away in python, they are replaced with an overall easier to learn language with many “intuitive” features. For this reason it is common and recommended by most professionals that people new to programming start with python.

  • Perl Programming

    Perl is an open-source, general-purpose interpreted programming language. Used often for CGI, Perl is also used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications. The Perl languages borrow features from other programming languages including C, shell scripting (sh), AWK, and sed. They provide powerful text processing facilities without the arbitrary data-length limits of many contemporary UNIX command line tools, facilitating easy manipulation of text files.

  • Android

    Android is an operating system based on the Linux kernel, and designed primarily for touch screen mobile devices such as smart phones and tablet computers. Android is a Linux-based software system, and similar to Linux, is free and open source software. This means that other companies can use the Android operating developed by Google and use it in their mobile devices.Android gives you a world-class platform for creating apps and games for Android users everywhere, as well as an open marketplace for distributing to them instantly.

Monday, December 20, 2010

Posted by venu k
20 comments | 12:00 PM

#!/bin/bash
# SCRIPT: armstrongnumber.sh
# USAGE: armstrongnumber.sh
# PURPOSE: Check if the given number is Armstrong number ?
# \\\\ ////
# \\ - - //
# @ @
# ---oOOo-( )-oOOo---
# Armstrong numbers are the sum of their own digits to the power of
# the number of digits. As that is a slightly brief wording, let me
# give an example:
# 153 = 1³ + 5³ + 3³
# Each digit is raised to the power three because 153 has three
# digits. They are totalled and we get the original number again!
#Notice that Armstrong numbers are base dependent,but we'll mainly be
# dealing with base 10 examples.The Armstrong numbers up to 5 digits
# are 1 to 9,153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727,93084
#
#####################################################################
# Script Starts Here #
#####################################################################

echo -n "Enter the number: "
read Number
Length=${#Number}
Sum=0
OldNumber=$Number

while [ $Number -ne 0 ]
do
Rem=$((Number%10))
Number=$((Number/10))
Power=$(echo "$Rem ^ $Length" | bc )
Sum=$((Sum+$Power))
done

if [ $Sum -eq $OldNumber ]
then
echo "$OldNumber is an Armstrong number"
else
echo "$OldNumber is not an Armstrong number"
fi


OUTPUT:
# sh armstrongnumber.sh
Enter the number: 8208
8208 is an Armstrong number
# sh armstrongnumber.sh
Enter the number: 4210818
4210818 is an Armstrong number
# sh armstrongnumber.sh
Enter the number: 4376541
4376541 is not an Armstrong number

20 comments:

  1. output error!!!!!!

    ReplyDelete
  2. Given me error details. It's working fine for me.

    ReplyDelete
  3. whats the use of #

    ReplyDelete
    Replies
    1. its use for special type of length of a string in shell scripts

      Delete
  4. thank q by antony

    ReplyDelete
  5. if u dont know the use of # . F##k u then.

    ReplyDelete
  6. Selenium is a package of many automatic testing resources, each of them providing to various assessment requirements.
    Each one of these instruments fall under exactly the same umbrella of open source category and supports just webbased s/w testing . For more info on this see this link

    ReplyDelete
  7. guys, what is the use of Oldnumber? please?

    ReplyDelete
  8. Power=$(echo "$Rem ^ $Length" | bc )

    explain this line, what is | bc

    ReplyDelete
  9. Your blog is very interesting

    ReplyDelete
  10. I will see and refer some information in your post.

    ReplyDelete
  11. very informative and knowledgeable

    ReplyDelete
  12. Really great blog, it's very helpful and has great knowledgeable information.
    Sailpoint Online Training

    ReplyDelete
  13. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea.
    here by i also want to share this.
    SAP WM Online Training

    ReplyDelete