Monday, June 11, 2007

An easy problem!

Try to code this easy problem:
Write a function which calculates the sum of the ASCII's code of all characters in an string. In C/C++ one may write as follows:

int Sum (char *S)
{
  int Result= 0;
  int i= 0;
  for ( S [i]!= 0; ++i)
  {
    Result+= S [i];
  }
  return Result;

}


Is it correct? Does this function produce the correct answer, always?

P.S. I love PASCAL!!??

No comments: