Write a function that reads stock share price at of N industries for M days as a two dimensional array and prints the diagonal price of the stock .Sample Input2 ( number of industries)3 ( number of days)300 670 2056 45 100Sample Output30045
Question
Write a function that reads stock share price at of N industries for M days as a two dimensional array and prints the diagonal price of the stock .Sample Input2 ( number of industries)3 ( number of days)300 670 2056 45 100Sample Output30045
Solution
Sure, here is a Python function that does what you asked for:
def print_diagonal_prices(n, m, prices):
for i in range(min(n, m)):
print(prices[i][i])
# Sample usage:
n = 2
m = 3
prices = [[300, 670, 205], [56, 45, 100]]
print_diagonal_prices(n, m, prices)
This function takes as input the number of industries n, the number of days m, and a two-dimensional list prices where prices[i][j] is the price of the stock of the i-th industry at the j-th day. It then prints the prices along the diagonal, i.e., the prices prices[i][i] for i from 0 to the minimum of n and m - 1.
In the sample usage, the function will print:
300
45
This is because the prices along the diagonal are 300 (from the first industry at the first day) and 45 (from the second industry at the second day).
Similar Questions
Write a C program that calculates the sum of both diagonals in a square matrix. Implement a function that takes a square matrix and its size as input and returns the sum of the main diagonal and anti-diagonal elements.Input3 31 2 3 4 5 6 7 8 9
You are given an integer array prices where prices[i] is the price of a given stock on the ith day.On each day, you may decide to buy and/or sell the stock. You can only hold at most one share of the stock at any time. However, you can buy it then immediately sell it on the same day.Find and return the maximum profit you can achieve.
Write a C program that calculates the sum of both diagonals in a square matrix. Implement a function that takes a square matrix and its size as input and returns the sum of the main diagonal and anti-diagonal elements.
Problem statementRaj is working on a data analysis project and needs help creating a program that processes a 2D array. This program includes functions to calculate the average value of each row in a 2D array. The program should consist of several functions:calculateRowAverage(cols, row): Calculates the average of a single row in a 2D array.calculateAverages(rows, cols, arr, averages): Computes and stores the averages for each row in the 2D array.displayAverages(rows, averages): Displays the row number and its average value.Input format :The first line of input consists of two integers, rows and cols, representing the dimensions of the 2D array.The second line of input consists of the elements arr[i] of the 2D array, where each element is a double.Output format :The output displays the average value of each row as a double datatype value, rounded off two decimal points in the specified format:Average of each row:Row 1: [row1_avg]Row 2: [row2_avg]Row 3: [row3_avg]Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1 ≤ rows and cols ≤ 51.0 ≤ arr[i] ≤ 5.0Max_Rows and Cols = 100Sample test cases :Input 1 :3 31.7 2.9 3.54.2 5.7 6.87.2 8.1 9.6Output 1 :Average of each row:Row 1: 2.70Row 2: 5.57Row 3: 8.30Input 2 :2 26.8 1.25.6 8.9Output 2 :Average of each row:Row 1: 4.00Row 2: 7.25Input 3 :5 52.2 3.8 4.3 5.8 9.26.7 7.1 8.8 9.2 10.711.7 12.8 13.7 14.3 15.316.2 17.4 18.2 19.2 20.121.3 22.7 23.4 24.3 25.7Output 3 :Average of each row:Row 1: 5.06Row 2: 8.50Row 3: 13.56Row 4: 18.22Row 5: 23.48
You are working on a data analysis project where you need to process an array of opening stock prices containing 10 days of data as float datatype.Question:Consider a scenario where you have been given an array of integers representing the daily stock prices of a company for a given period. You are also provided with an ArrayList of stock prices for the same period You are required to implement a program that performs the following tasks:Calculate the average stock price:Write a method, calculateAveragePrice, that takes the array of stock prices as input and returns the average price of the stocks.Find the maximum stock price:Write a method, findMaximumPrice, that takes the array of stock prices as input and returns the maximum price among all the stocks. Determine the occurrence count of a specific price:Write a method, countOccurrences, that takes the array of stock prices and a target price as input and returns the number of times the target price occurs in the array. Compute the cumulative sum of stock prices:Write a method, computeCumulativeSum, that takes the ArrayList of stock prices as input and returns a new ArrayList containing the cumulative sum of prices at each position.Note:Assume both the array and ArrayList of stock prices is not null and contains at least one element.You are allowed to use loops (for, while) for array and ArrayList.Write the code for the above scenario, including the required methods and their implementations. Remember to use appropriate variable names and follow coding best practices.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.