Drill

ProblemsC# › finance

Profit margin in permille

mediumfinanceMathC#

A store wants its margin as a whole per-mille number: how much of each minor unit of revenue survives as profit.

ProfitMargin(revenue: int, cost: int) → int

C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

public int ProfitMargin(int revenue, int cost) {
    
}

Worked examples

CallResult
ProfitMargin(1000, 600)400
ProfitMargin(1000, 1000)0
ProfitMargin(1000, 1200)-200
ProfitMargin(0, 100)0

Hint

Subtract the cost from revenue, scale by 1000, divide by revenue.

Reference solution in C#
public int ProfitMargin(int revenue, int cost) {
    if (revenue <= 0) return 0;
    return ((revenue - cost) * 1000) / revenue;
}

The same problem in another language

More finance problems in C#