Logo 
Search:

Unix / Linux / Ubuntu Answers

Ask Question   UnAnswered
Home » Forum » Unix / Linux / Ubuntu       RSS Feeds
  Question Asked By: Zubair Siyal   on Aug 07 In Unix / Linux / Ubuntu Category.

  
Question Answered By: Kirtiranjan Sahoo   on Aug 07

#!bin/bash

read -p "Enter a number : " n
sum=0
for (( i=1;i<=n;i++ ))
do
dig=$(( $n % 10 ))
sum=$(( $sum + $dig ))
n=$(( $n / 10 ))
done
echo "The sum of digits are : $sum"

Share: