22 October 2012

Swapping two numbers using Multiplication and Divide

5 comments

Q. How do I swap two numbers without using addition and subtraction in Bash


Ans:

#!/bin/bash
read -p "Enter first number :" first
read -p "Enter second number:" sec
echo ""
echo -e "Number before swapping is $first and $sec \n"
#swapping logic
first=$((first*sec))
sec=$((first/sec))
first=$((first/sec))
echo -e "Number after swapping is $first and $sec \n"

Output


Enjoy :)


If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

5 comments:

  1. Your words are incredibly uplifting; thank you for sharing such positivity! IOGames Top is my go-to site for the best free online games! The collection is huge and always growing. Highly recommend! Check it out and start playing today!

    ReplyDelete
  2. This post was short but very useful! Visit the profile of Reaction Time Test to train your reaction time. Taking a Reaction Time Test regularly can help track improvements in response speed and overall cognitive sharpness.

    ReplyDelete