Tuesday, January 12, 2016

Shell program to check whether given number is divisible by 7 or not, if not find the previous and next number which is divisible by 7.

# 7divisible.sh
# Program :         To check whether given number is divisible by 7 or not, if not  
                             find the previous and   next number which is divisible by 7.
# Author :            sujith
# Date :               16/03/2015

clear
echo "Enter the number "
read n
c=`expr $n % 7`
if test $c -eq 0
 then
        echo "$n is divisible by 7"
else
     echo "$n is not divisible by 7"
     n1=`expr $n - $c`
     n2=`expr $n - $c + 7`
     echo "Previous number which is divisible is " $n1
     echo "next number which is divisible is     " $n2
fi






OUTPUT:
[141740@localhost ~]$ sh 7divisible.sh
Enter the number
52
52 is not divisible by 7
Previous number which is divisible is  49
next number which is divisible is      56
[141740@localhost ~]$

Enter the number
49
49 is divisible by 7
[141740@localhost ~]$



1 comment: