Question

Write an interactive program using recursion for the following:

(a) To find the HCF of two given numbers.

(b) To find the GCD of two given numbers.

(c) To find the factorial of a given number.

15 Sep 2022
Answer :
Word Count : 272

(a) To find the HCF of two given numbers:

#include <stdio.h>

int hcf(int a, int b) {
    if (b == 0) {
        return a;
    }
    return hcf(b, a % b);
}

int main() {
    int a, b;
    printf("Enter two numbers: ");
    scanf("%d%d", &a, &b);
    int result = hcf(a, b);
    printf("HCF: %d ", result);
    return 0;
}
__________ _____ ___ _____ ___.
____ __________ _____ ________ __________.
_____ ______ __________ ___ ______ __________ ____ _______ _________ __________.
______ _______ ____ _________ ___ ________ ________ ______ ________.
_______ __________ ______ ____ ___.
___ _______ ___ ______ _____.
______ ________ _____ ___ ____ __________ ___ _______ _______ ________ ____ _____.
_________ ____ _____ ______ ____ ______ ___ ______ _____ ____.
__________ ________ ___ ______ __________ ___.
_________ ________ _______ ________ _________ ___ _______ _________ _____ ____.
_______ _____ _____ _______ ___ _____.
_________ ________ _________ ___ _____.
____ _________ __________ ______ ___ ____ ___ ________ _____ _______ _________ ________.
________ ___ _______ _________ ________ ___.
________ _________ ___ _____ ____ _____ _______ _______ ______ ____ _______ ____.
___ ______ ___ __________ ________ ______ _______ __________ ________ _______ ______ __________.
______ _____ _________ ____ ____ ____ ______.
__________ ________ ____ ________ _________ _____ ___ ____ _______ _____ ___ _________.
_______ _____ _____ _________ ________.
____ ____ __________ __________ ____ ___ _______ ______.
_______ ___ _____ ____ _______ ______ ______ ___ ___.
________ ________ __________ ___ ____ ____.
____ ____ __________ _________ ______.

IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
'; fetch( "query.php?type=1&method=0&lr=0&app=401&mycartproduct=1", { method: "GET", cache: "no-store" } ) .then(function(response) { if (!response.ok) { throw new Error( "HTTP " + response.status ); } return response.text(); }) .then(function(html) { loader.innerHTML = html; /* Your existing function, if available. */ if (typeof updateTotals === "function") { updateTotals(); } else { calculateCartTotal(); } }) .catch(function(error) { console.error( "Cart loading error:", error ); loader.innerHTML = '
Unable to load cart.
'; });}/* ========================================================= CALCULATE TOTAL========================================================= */function calculateCartTotal() { let subtotal = 0; /* Looks for .item-price inside AJAX products. Examples accepted: ₹200 ₹200.00 Rs 200 Rs. 200 200 200.00 */ const prices = document.querySelectorAll( '#loadmycart .item-price' ); prices.forEach(function(element) { let text = element.textContent || ''; text = text .replace(/₹/g, '') .replace(/Rs\.?/gi, '') .replace(/,/g, '') .trim(); let value = parseFloat(text); if (!isNaN(value)) { subtotal += value; } }); updateCartDisplay(subtotal);}/* ========================================================= UPDATE TOTAL DISPLAY========================================================= */function updateCartDisplay(total) { const subtotalElement = document.getElementById('subtotal'); const totalElement = document.getElementById('total'); const checkoutButton = document.getElementById('checkoutButton'); const noItems = document.getElementById('noitems'); const amount = Number(total) || 0; if (subtotalElement) { subtotalElement.textContent = '₹' + amount.toFixed(2); } if (totalElement) { totalElement.textContent = '₹' + amount.toFixed(2); } /* EMPTY CART */ if (amount
Top