Question

Write a program to find the smallest element in an array.

23 Apr 2024
Answer :
Word Count : 280

To find the smallest element in an array, you can iterate through each element of the array and keep track of the smallest element found so far. Here's a simple implementation in Python:

```python
def find_smallest_element(arr):
    # Check if the array is empty
    if not arr:
        return None
    
    # Initialize the smallest element as the first element of the array
    smallest = arr[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