RosettaCodeData/Task/Dot-product/C-sharp/dot-product-1.cs
2023-07-01 13:44:08 -04:00

25 lines
431 B
C#

static void Main(string[] args)
{
Console.WriteLine(DotProduct(new decimal[] { 1, 3, -5 }, new decimal[] { 4, -2, -1 }));
Console.Read();
}
private static decimal DotProduct(decimal[] vec1, decimal[] vec2)
{
if (vec1 == null)
return 0;
if (vec2 == null)
return 0;
if (vec1.Length != vec2.Length)
return 0;
decimal tVal = 0;
for (int x = 0; x < vec1.Length; x++)
{
tVal += vec1[x] * vec2[x];
}
return tVal;
}