Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок+ 3
If input is [1,2,3] then how get output [1,2,4]...
Note that the numbers are in array..
9 ответов
+ 5
In Python
a = [1,2,3]
b = [2**(i-1) for i in a]
print(a)
print(b)
+ 8
arr[2] += 1
Without more context, this is all I can produce.
+ 6
input : x
output : 2^(x-1)
+ 3
Assuming, input = [1, 2, 3, 4, 5,...]
1) Let (output) be an empty array [ ].
2) Use a for loop and let (x) be the i'th item of the array (input).
3) Set i'th item of the (output) to :
3.1) 2 to the power of (x - 1).
Then the output will be [1, 2, 4, 8, 16,...].
3.2) (x + 1) if i is greater than equal to 2 and (x) if not. Then the output will be [1, 2, 4, 5, 6,...].
3.3) (x + 1) if i is equal to 2 and (x) if not. Then the output will be [1, 2, 4, 4, 5,...]
Depending on the output you want choose any one of 3.1, 3.2 or 3.3 and this concept will work on any language that supports assignment, if statement and for statement.
+ 3
desai amber Please choose a specific programing language and an example of the output array with more than three values. Ex : python, [1, 2, 4, 8, 16...]
Then we can help you to figure out the appropriate equation and also make you understand it.
+ 2
This is the code for python:
import math
input = [1, 2, 3, 4, 5]
output = []
for i in input:
output.append(math.pow(2, i - 1))
print(output)
This is the code for JavaScript:
var input = [1, 2, 3, 4, 5];
var output = [];
for (var i = 0; i < input.length; i++)
{
output.push(Math.pow(2, input[i] - 1));
}
+ 1
I understand both of your answers.. Thanks Muhammad hasan and Cyrus Ornob Corraya..
0
ok
0
Please friend Cyrus Ornab Corraya.. Please type full programme in sequence.. I don't know about more in Array structure..