{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Problem 1\n", "Given an array, find out the product of its element using recursion.\n", "- Input: [1, 2, 3, 4, 5] \n", "- Output: 120" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "20" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def productOfArray(arr):\n", " \"\"\"\n", " calculates the product of all the numbers in array\n", " \"\"\"\n", " if len(arr) == 0:\n", " return 1\n", " else:\n", " return len(arr) * productOfArray(arr[1:])\n", "\n", "productOfArray([1, 2, 3, 4, 5])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "interpreter": { "hash": "40d3a090f54c6569ab1632332b64b2c03c39dcf918b08424e98f38b5ae0af88f" }, "kernelspec": { "display_name": "Python 3.8.3 ('base')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.3" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }