Register
It is currently Tue Sep 23, 2014 8:21 pm

division by zero


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Fri Dec 05, 2008 8:46 pm   

Joined: Fri Dec 05, 2008 8:25 pm
Posts: 1
i'm in class now for this stuff, but i'm having some difficulty writing a script for this. its a script that reads 2 integer values and does multiplication, divison, subtraction, addition and mod. but if the second number is zero it does not do the division and mod. and to be perfectly honest i don't even know what "mod" is. if someone could help out, that would be great. thanks.


Top
 Profile  
 PostPosted: Sun Dec 07, 2008 4:12 am   

Joined: Tue Dec 05, 2006 8:37 pm
Posts: 30
Location: Thiruvananthapuram / India
Dear Friend,

Modulo or modulus operation finds the reminder of division of one number by another. Mathematical operator is %. For instance, 5%3=2.

Now, here is the script:

Code:

#!/bin/bash

read -p "First integer: " num1
read -p "Second integer: " num2

# Addition
echo "Sum = $((num1+num2))"

# Subtraction
echo "Difference = $((num1-num2))"

# Multiplication
echo "Product = $((num1*num2))"

if [ $num2 -eq 0 ]
then
  echo "Division and modulus are not possible."
  exit 0
fi

# Division
echo "Division = $((num1/num2))"

# Modulus
echo "Modulus = $((num1%num2))"



Let me know if this helps :-)

Thanks,
Lijeesh


Top
 Profile WWW YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP