0
to get N elements in an array and a number to be multiplied with the array elements. wants to display the multiplied with the ar
Ramu wants to get N elements in an array and a number to be multiplied with the array elements. He wants to display the multiplied result in descending order. Help Ramu to complete this task. Input Format Number of array elements in the first line - N N array elements in second line separated by a space Number to be multiplied with array elements Constraints Positive Integers Only. Output Format Array elements in descending order after multiplied with the given number (space separated) Sample Input 0 5 40 10 30 15 4 Sample Output 0 160 120 60 40 Sample Input 1 5 10 30 20 50 40 2 Sample Output 1 100 80 60 40 20
16 Réponses
+ 2
Bro, I will help but I'm not writing you the full code, it won't help you learn that way. Sketch the code and I will help you fix the problem you run into during the tryout 👌
+ 1
Will you share a link to your tryout code? I need to see where the problem is. Without a code I have nothing to review, thus Idk what to suggest ...
Save your code bit and share its link in post's Description ☝
https://www.sololearn.com/post/75089/?ref=app
+ 1
Are you okay bro?
That was the task Description, not your code, I'm waiting for your tryout code ...
Go through this ...
1. Read <N>, convert it to integer
2. Read a string containing numbers, separated by space, name it <nums>
2.a. Split <nums> by space
2.b. Use a loop to convert each elements in <nums> to integer
3. Read <multiplier> convert to integer
4. Use a loop to multiply each element in <nums> by <multiplier>
5. Use list.sort() method to sort <nums>. Remember to set the optional 'reverse' argument to true in order to sort in descending order.
Good luck! 👍
+ 1
Hang on, let me check it first
If you please, move this code up to the code bit you sent earlier above.
It's easier in code bit cause we can refer line numbers. We can't refer line numbers in raw text. It's just easier for pointing out problem location by line numbers ...
+ 1
Bro this looks different, it works but in different way.
This code doesn't ask for the multiplier value, it uses the list length instead, and it's doing different calculation ...
0
Okay bro
0
# Python program to update every array element with
# multiplication of previous and next numbers in array
def modify(arr, n):
# Nothing to do when array size is 1
if n <= 1:
return
# store current value of arr[0] and update it
prev = arr[0]
arr[0] = arr[0] * arr[1]
# Update rest of the array elements
for i in range(1, n-1):
# Store current value of next interaction
curr = arr[i];
# Update current value using previous value
arr[i] = prev * arr[i+1]
# Update previous value
prev = curr
# Update last array element
arr[n-1] = prev * arr[n-1]
# Driver program
arr = [2, 3, 4, 5, 6]
n = len(arr)
modify(arr, n)
for i in range (0, n):
print(arr[i],end=" ")
Is it crt bro?
0
Ohh ok bro.... Then what can i do pls show the code bro....
0
Bro it shows error in test case 1 bro but it's passes test case 2
0
Bro i can't able to share the link bro... It shows no o\p in test case 0 and it passes the test case 1 bro... Pls help me bro
0
Program
- 1
https://code.sololearn.com/cXoBEVRyPSd5/?ref=app
Pls help me to solve this qstn in python3
- 4
Pls send the full program bro