Question

Write a Shell Script program to find Greatest Common Divisor (GCD) for any two numbers. Ensure that your script carries out basic error checking

15 Sep 2022
Answer :
Word Count : 315

To write a Shell Script program to find the Greatest Common Divisor (GCD) for any two numbers, we can use the Euclidean algorithm. The Euclidean algorithm is a simple and efficient algorithm for finding the GCD of two numbers.

Here is a sample script to find the GCD of two numbers using the Euclidean algorithm:

#!/bin/bash

echo "Enter the first number:"
read num1

echo "Enter the second number:"
read num2

# Basic error checking
if [ "$num1" -le 0 ] || [ "$num2" -le 0 ]
then
    echo "Error: Please enter

_______ __________ ________ ________ ___ ______.
_______ _______ __________ __________ _________ ________.
_______ ______ __________ ______ _____.
_____ ________ ____ __________ ____.
______ ____ ______ ___ ________ _______ __________ _________ ___.
______ _____ __________ _____ __________ _________ _________ _________ _____.
________ ______ ________ ______ ________ _____ ___ ____ ___.
____ __________ ______ ___ ______ __________ _____ _________ ___ ___ ________.
_________ ___ _______ _______ ____ ________ __________ __________ ___ ____ ________.
_______ ______ __________ _______ _______ __________ _______ ______ ______ _____ _____.
___ _______ ___ _______ __________ _______ ____ ____ _________ ________.
__________ _______ ____ ________ _________ ___ ______.
____ __________ _______ ___ _____ _________ ________ _______ __________ __________ __________.
_____ __________ ________ ____ _____ _________ _____ _______.
___ _______ ____ ___ ________ _____ ______ __________ ______.
________ ___ ___ ____ _______ _____ ______ ______ ___ _______ ______ _________.
_________ ________ ______ ________ ______ ______ ________.
______ ________ _____ _____ ______ _________ ______ ____ _____ _________ _________.
__________ ___ _____ _________ ________ ___ _________ _____ ______ __________ ______.
________ __________ __________ __________ __________ ______ ____ ____ __________ _______ ___.
____ __________ _______ __________ ____ ___ _______ _________ _________ ___ ___.
___ _______ _______ _________ ______ ___.
________ ___ __________ ______ __________ __________ _____ _________ __________ _________.
_______ _________ ______ ___ ______ __________ ______ ______ _______ _________.
_______.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU MCS 22 2022 2023 - Write a Shell Script program to find Greatest Common Divisor (GCD) for | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→