Cara menggunakan cot in python
Pos TerkaitHow do i turn off javascript in safari?F.A.Q Why do I need JavaScript enabled on Apple Safari? Apple Safari comes built-in with a JavaScript engine that makes website elements interactive. ...
Cara menggunakan NP.RAVEL pada Python
Artikel ini adalah kelanjutan dari tulisan sebelumnya: belajar Python NumPy dengan IPython. Kali ini kita akan belajar konsep pengubahan bentuk matriks pada NumPy array.Pada bahasa pemrograman ...
How do you multiply an entire array in python?
import numpy as npA = np.array[[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]]B = np.array[[[11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]]print[np.multiply[A[ 0,:], B[ 1,: ...
Library apa saja yang ada pada python?
Diterbitkan pada 22 September 2018 Banyaknya kelebihan pada pemrograman pythno seperti efisiensei, keterbacaan kode dan kecepatan telah membuat python menjadi bahasa pemrograman yang banyak digunakan ...
Cara menggunakan math degrees python
next → ← prevTable of ContentsWhat is Math Module in Python?Constants in Math ModuleEulers NumberMathematical Operations with Math ModuleCalculating the Ceiling and the Floor ValueCalculating ...
How do you change the color of an image in python?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. ...
How do i use xcorr in python?
Jacob FerusApr 213 min read Photo by Agê Barros on UnsplashImagine you have two time series that you know are correlated, but when calculating the correlation no significant value is shown. This is ...
How to create 2d array in python using numpy
IntroductionMethod 1: Using Nested ListsCreating a 2D Array Loaded with ZerosAssigning Values to The 2D ArrayMethod 2: Using DictionariesMethod 3: Using NumPyCreating 2D Arrays Loaded with ...
Cara cek library python di cmd
Saya baru saja menginstall python versi 3.7 dan 2.7. Saya ingin mengecek python berapa saja yang sudah terinstall di komputer saya dengan mengetikan code berikut di cmd: python --version namun ...
Cara menggunakan xcorr python
Last update on August 19 2022 21:51:44 [UTC/GMT +8 hours]NumPy Statistics: Exercise-9 with SolutionWrite a NumPy program to compute cross-correlation of two given arrays.Sample Solution:- Python ...
Cara menggunakan python random get seed
NumPy random.rand [] berfungsi dalam Python digunakan untuk mengembalikan nilai acak dari distribusi seragam dalam bentuk tertentu. Fungsi ini membuat larik dari bentuk yang diberikan dan diisi ...
Cara menggunakan NUMPY.NDARRAY pada Python
Numpy Array¶Membuat Array dari Python List¶In [2]:# integer array: np.array[[1, 2, 3, 4]] Tidak seperti Python lists, Numpy array elemen-elemennya bertipe data sama. Apabila tipe data nya ...
Apa fungsi numpy pada python?
Python adalah bahasa pemrograman yang interaktif, portabel, dan object oriented. Bahasa pemrograman open source ini bisa dijalankan di berbagai macam system, termasuk Linux, macOS, dan Windows. ...
Cara menggunakan create rgb image python
Perkembangan Artificial Intelligence [AI] saat ini sangat cepat baik dalam metode dasar maupun penerapan di lapangan. Banyak instansi yang membutuhkan AI, dari kedokteran, pertanian, hingga ...
Cara menggunakan NP.ALL pada Python
Python NumPy any[] digunakan untuk memeriksa apakah semua elemen array di sepanjang sumbu yang disebutkan bernilai True atau False. Berarti, jika ada semua elemen pada sumbu tertentu, adalah benar , ...
Cara menggunakan NUMPY.DIFF pada Python
Selisih [Difference]Selisih diskrit berarti mengurangkan dua elemen array secara berurutan.Misalnya: untuk array [1, 2, 3, 4], selisih diskritnya menjadi [2-1, 3-2, 4-3] = [1, 1, 1]Untuk mencari ...
View Discussion
Improve Article
Save Article
View Discussion
Improve Article
Save Article
We are given an array, and we have to calculate the product of an array using both iterative and recursive methods.
Examples:
Input : array[] = {1, 2, 3, 4, 5, 6} Output : 720 Here, product of elements = 1*2*3*4*5*6 = 720 Input : array[] = {1, 3, 5, 7, 9} Output : 945
Iterative Method: We initialize result as 1. We traverse array from left to right and multiply elements with results.
Implementation:
C++
#include
using
namespace
std;
int
multiply[
int
array[],
int
n]
{
int
pro = 1;
for
[
int
i = 0; i < n; i++]
pro = pro * array[i];
return
pro;
}
int
main[]
{
int
array[] = {1, 2, 3, 4, 5, 6};
int
n =
sizeof
[array] /
sizeof
[array[0]];
cout
Javascript
var
arr = [ 1, 2, 3, 4, 5, 6 ];
function
multiply[] {
var
pro = 1;
for
[i = 0; i < arr.length; i++]
pro = pro * arr[i];
return
pro;
}
document.write[multiply[]];
Time Complexity: O[n]
Recursive Method:
C++
#include
using
namespace
std;
int
multiply[
int
a[],
int
n]
{
if
[n == 0]
return
[a[n]];
else
return
[a[n] * multiply[a, n - 1]];
}
int
main[]
{
int
array[] = {1, 2, 3, 4, 5, 6};
int
n =
sizeof
[array] /
sizeof
[array[0]];
cout
Javascript
var
arr = [ 1, 2, 3, 4, 5, 6 ];
function
multiply[a , n] {
if
[n == 0]
return
[a[n]];
else
return
[a[n] * multiply[a, n - 1]];
}
document.write[multiply[arr,
arr.length - 1]];
Time Complexity: O[n]
Auxiliary Space: O[n]
Using C++ STL:
C++
#include
#include
using
namespace
std;
int
multiply[
int
array[],
int
n]
{
int
pro = 1;
return
accumulate[array, array + n, pro, multiplies[]];
}
int
main[]
{
int
array[] = {1, 2, 3, 4, 5, 6};
int
n =
sizeof
[array] /
sizeof
[array[0]];
cout