he stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of stock’s price for all n days. The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day, for which the price of the stock on the current day is less than or equal to its price on the given day. Now, you need to find out the span values for the given number of days and their daily prices. For example, if an array of 7 day's prices is given as {100, 80, 60, 70, 60, 75, 85}, then the span values for corresponding 7 days are {1, 1, 1, 2, 1, 4, 6} . FUNCTIONAL REQUIREMENTS: void stockSpan(int,int*);
Answers
Answered by
0
Explanation:
answer: 64, 72 73, 726, 825, 52, 62, 626,
Answered by
0
Answer:
#include <stdio.h>
void stockSpan(int price[], int n, int S[])
{
S[0] = 1;
for (int i = 1; i < n; i++) {
S[i] = 1;
for (int j = i - 1; (j >= 0) && (price[i] >= price[j]); j--)
S[i]++;
}
}
void printArray(int arr[], int n)
{
for (int i = 0; i < n; i++)
printf("%d ", arr[i]);
}
int main()
{
int price[] = { 100, 80, 60, 70, 60, 75, 85 };
int n = sizeof(price) / sizeof(price[0]);
int S[n];
stockSpan(price, n, S);
printArray(S, n);
return 0;
}
Explanation:
The above C program will solve stock span problem.
Similar questions
Political Science,
4 months ago
Physics,
9 months ago
Math,
1 year ago
India Languages,
1 year ago
English,
1 year ago