Implement the following function:
float CumulativeDiscount(float arr[], int n);
.
This is a template based question, DO NOT write the "main" function.
Your code is judged by an automated system, do not write any additional welc
messages.
"Save and Test" only checks for basic test cases, more rigorous cases will be used
code while scoring.
Additional score will be given for writing optimized code both in terms of memory a
time.
.
Now let's start coding :
R2
с
C++
Java
C#
The function accepts a float array 'arr' comprising 'n' discount
percentages applied on marked price of an object. Order of discounts
in 'arr' is same in which discounts are applied on the object.
Implement the function to calculate the cumulative discount
percentage and return the same.
Discounted price = Marked Price * (100 - discount%) / 100
Discount% = 100 - (Discounted Price * 100 / Marked Price)
For eg, if marked price is $100 and discounts 10%, 20%, 30% are
applied in this sequence then,
After 10% discount, price = $100 * (100 - 10) / 100 = $90
After 20% discount, price = $90 * (100 - 20) / 100 = $72
After 30% discount, price = $72 * (100 - 30) / 100 = $50.4
For final discounted price, discount% = 100 - (50.4 * 100 / 100)
49.60%.
Thus, cumulative discount% is 49.60%.
Assumption:
n > 0
Read-only code below...
1 float CumulativeDiscount(float arr[], int n);
2 int main()
3 {
4 //Input read from STDIN
5 float result CumulativeDiscount(arr, n);
6 //Value in result printed to STDOUT
7 return ;
8 }
9
O Write your code below...
10 float CumulativeDiscount(float arr[], int n)
11 {
12 /* Write your code here. */
13 }
14
15
16
0 =< Discount% <100
Consider marked price to be $100
Note: Do not round off your result, it will be automatically rounded
off up to 2 decimal places and then displayed.
Sample Input
arr: 40.00 20.00
Sample Output
52.00
Answers
Answered by
0
Answer:
EASY Man just try if you don't get it i will help you ..
.
.
.
.
.
Similar questions