mirror of
https://bitbucket.org/Mattrixwv/csclasses.git
synced 2025-12-06 18:23:58 -05:00
Added getSum and getProd functions for arrays
This commit is contained in:
@@ -23,6 +23,7 @@ Copyright (C) 2020 Matthew Ellison
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
|
||||||
|
|
||||||
@@ -459,5 +460,40 @@ namespace mee{
|
|||||||
primes.Sort();
|
primes.Sort();
|
||||||
return primes;
|
return primes;
|
||||||
}
|
}
|
||||||
|
//These functions get a value from combining elements in an array
|
||||||
|
public static int getSum(List<int> ary){
|
||||||
|
return ary.Sum();
|
||||||
|
}
|
||||||
|
public static long getSum(List<long> ary){
|
||||||
|
return ary.Sum();
|
||||||
|
}
|
||||||
|
public static BigInteger getSum(List<BigInteger> ary){
|
||||||
|
BigInteger sum = 0;
|
||||||
|
foreach(BigInteger num in ary){
|
||||||
|
sum += num;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
public static int getProd(List<int> ary){
|
||||||
|
int prod = 1;
|
||||||
|
foreach(int num in ary){
|
||||||
|
prod *= num;
|
||||||
|
}
|
||||||
|
return prod;
|
||||||
|
}
|
||||||
|
public static long getProd(List<long> ary){
|
||||||
|
long prod = 1;
|
||||||
|
foreach(long num in ary){
|
||||||
|
prod *= num;
|
||||||
|
}
|
||||||
|
return prod;
|
||||||
|
}
|
||||||
|
public static BigInteger getProd(List<BigInteger> ary){
|
||||||
|
BigInteger prod = 1;
|
||||||
|
foreach(BigInteger num in ary){
|
||||||
|
prod *= num;
|
||||||
|
}
|
||||||
|
return prod;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user