Question: In c# how do I evenly divide 100 into 7?

So the result would be 

1. 16
2. 14
3. 14
4. 14
5. 14
6. 14
7. 14

The code below is incorrect as all 7 values are set to 15 (totalling 105).

```
        double [] vals = new double[7];
        for (int i = 0; i < vals.Length; i++)
        {
            vals[i] = Math.Ceiling(100d / vals.Length);
        }

```

Is there an easy way to do this in c#?

Thanks

Answer: 
Here you go: 

```
Func<int, int, IEnumerable<int>> f = (a, b) => 
 Enumerable.Range(0,a/b).Select((n) => a / b + ((a % b) <= n ? 0 : 1))

```

Good luck explaining it in class though :)
Not sure if this is exactly what you are after, but I would think that if you use Math.ceiling you will always end up with too big a total. Math.floor would underestimate and leave you with a difference that can be added to one of your pieces as you see fit.

For example by this method you might end up with 7 lots of 14 giving you a remainder of 2. You can then either put this 2 into one of your pieces giving you the answer you suggested, or you could split it out evenly and add get two pieces of 15 (as suggested in one of the comments)