/* This returned -2 */
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Calculate("1701209041");
}
private static void Calculate(string s)
{
/*
if the number its 1701209041-1, the formula will be:
1x3 + 7x2 + 0x9 + 1x8 + 2x7 + 0x6 + 9x5 + 0x4 + 4x3 + 1x2 =
98. the
modulo of the divison of 98 by 11 its 10. Then 11 - 10 = 1,
the Number
that check if its valid it 1 like the initial number so its
a valid
sequence.
*/
try
{
char[] cDigits = s.ToCharArray();
//int[] digits = Array.ConvertAll<char, int>(cDigits, new
Converter<char, int>(ConvertCharToInt));
int[] digits = Array.ConvertAll<char, int>(cDigits,
Convert.ToInt32);
double calculo;
calculo = (digits[0] * 3) + (digits[1] * 2) + (digits[2] *
9) + (digits[3] * 8) + (digits[4] * 7) + (digits[5] * 6) + (digits[6] * 5) +
(digits[7] * 4) + (digits[8] * 3) + (digits[9] * 2);
calculo %= 11;
calculo -= 10;
Console.WriteLine("The value is : " + calculo);
Console.Read();
}
catch (FormatException)
{
// Handle the exception.
}
}
private int ConvertCharToInt(char c)
{
return int.Parse(c.ToString());
}
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://cm.megasolutions.net/forums/default.aspx
<p><a href="http://feeds.feedburner.com/DotNetDevelopment"><img
src="http://feeds.feedburner.com/~fc/DotNetDevelopment?bg=99CCFF&fg=444444&anim=1"
height="26" width="88" style="border:0" alt="" /></a></p>
-~----------~----~----~----~------~----~------~--~---