onycro

Klausur BSZ IF

Apr 14th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.31 KB | None | 0 0
  1. public int PZ(string nr)
  2.  {
  3.      int pz = 0;
  4.      for (int i = 0; i < nr.Length; i++)
  5.      {
  6.          int stelle = (int)(nr[i] - '0');
  7.          stelle = (i % 2 == 0 ? stelle : stelle * 2);
  8.          pz += stelle % 10 + (stelle >= 10 ? 1 : 0);
  9.      }
  10.      pz %= 10;
  11.      return (10 - pz) < 10 ? 10 - pz : 0;
  12.  }
Advertisement
Add Comment
Please, Sign In to add comment