Custom Search

Friday 20 April 2012

Write a Linux shell script to print and add all even numbers between given range, Unix program to print and add all even numbers


Write a Linux shell script to print and add all even numbers between given range, Unix program to print and add all even numbers


Program


clear 
echo "Enter Starting no:"
read n1
echo "Enter Ending no:"
read n2


sum=0


for((i=n1;i<=n2;i++))
do
   if['expr $i%2'-eq 0]
   then 
      echo $1
      sum= 'expr $sum +$i'
   fi
 done


 echo "Sum :"$sum


Output:
Enter Starting no:
2


Enter Ending no:
8


2
4
6
8


Sum :20
<<< Previous  ||  Current  ||  Next >>>  

No comments:

Post a Comment

Laptops