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: 
To get my suggested result of 15, 15, 14, 14, 14, 14, 14:

```
// This doesn't try to cope with negative numbers :)
public static IEnumerable<int> DivideEvenly(int numerator, int denominator)
{
    int rem;
    int div = Math.DivRem(numerator, denominator, out rem);

    for (int i=0; i < denominator; i++)
    {
        yield return i < rem ? div+1 : div;
    }
}

Test:

foreach (int i in DivideEvenly(100, 7))
{
    Console.WriteLine(i);
}

```
Since this seems to be homework, here is a hint and not the full code.

You are doing Math.Ceiling and it converts 14.28 into 15.