Calculate the loss incurred in selling the given items at discounted price | C # implementation of the approach ; Function to return the x % of n ; Function to return the total loss ; To store the total loss ; Original price of the item ; The price at which the item will be sold ; The discounted price of the item ; Loss incurred ; Driver code ; Total items
using System ; class GFG { static float percent ( int n , int x ) { float p = n * x ; p /= 100 ; return p ; } static float getLoss ( int [ ] price , int [ ] quantity , int [ ] X , int n ) { float loss = 0 ; for ( int i = 0 ; i < n ; i ++ ) { float originalPrice = price [ i ] ; float sellingPrice = originalPrice + percent ( ( int ) originalPrice , X [ i ] ) ; float afterDiscount = sellingPrice - percent ( ( int ) sellingPrice , X [ i ] ) ; loss += ( ( originalPrice - afterDiscount ) * quantity [ i ] ) ; } return loss ; } public static void Main ( ) { int [ ] price = { 20 , 48 , 200 , 100 } ; int [ ] quantity = { 20 , 48 , 1 , 1 } ; int [ ] X = { 0 , 48 , 200 , 5 } ; int n = X . Length ; Console . Write ( getLoss ( price , quantity , X , n ) ) ; } }