-2

I'm trying to get % result of ( -1%26 ) the result should be 25 in python it's right but C# gives -1 as result why and how to get 25 in C# not -1

AwadhJY
  • 1
  • 2

1 Answers1

1

You can use a different kind of modulus function, like this:

int Modulus(int a, int b) { 
  return ((a % b) + b) % b; 
}
Console.WriteLine(Modulus(-1, 26)); // prints 25