Friday 27 March 2020

Write a shell script to count the number of occurrences of a particular digit in an 8 digit number input. 

PROGRAM
echo enter an 8 digit number
read d
echo enter a digit to find
read f
n=8
for((i=1;i<=n;i++))
do
      k=`echo $d|cut -c $i`
       if test $f -eq $k
       then
            cnt=`expr $cnt + 1`
        fi
done
echo the number of occurrences of number $f is $cnt





OUTPUT
enter an 8 digit number
12323332
enter a digit to find
2
the number of occurrences of number 2 is 3

No comments:

Post a Comment