# How to Find the Maximum Multiple in C

## The challenge

** Given** a

**,**

*Divisor and a Bound**Find the largest integer N*, Such That ,

**Conditions :**

is*N**divisible by divisor*is*N**less than or equal to bound*is*N**greater than 0*.

**Notes**

- The
passed to the function are*parameters (divisor, bound)**only positive values*. *It’s guaranteed that*a**divisor is Found**.Input » Output Examples

```
maxMultiple (2,7) ==> return (6)
```

**Explanation:**

** (6)** is divisible by

**,**

*(2)***is less than or equal to bound**

*(6)***, and**

*(7)***is > 0 .**

*(6)*```
maxMultiple (10,50) ==> return (50)
```

**Explanation:**

*(50)**is divisible by* ** (10)** ,

**is less than or equal to bound**

*(50)***, and**

*(50)***is > 0 .***

*(50)*```
maxMultiple (37,200) ==> return (185)
```

**Explanation:**

** (185)** is divisible by

**,**

*(37)***is less than or equal to bound**

*(185)***, and**

*(200)***is > 0 .**

*(185)*## The solution in C

Option 1:

```
int maxMultiple(int divisor, int bound) {
return bound / divisor * divisor;
}
```

Option 2:

```
int maxMultiple(int divisor, int bound) {
return bound - bound % divisor;
}
```

Option 3:

```
int maxMultiple(int divisor, int bound) {
while(bound>0) {
if(bound%divisor==0)
break;
else
bound--;
}
return bound;
}
```

## Test cases to validate our solution

```
#include <criterion/criterion.h>
int maxMultiple(int divisor, int bound);
Test(Maximum_Multiple, Check_Small_Positives)
{
cr_assert_eq(maxMultiple(2,7), 6);
cr_assert_eq(maxMultiple(3,10), 9);
cr_assert_eq(maxMultiple(7,17), 14);
}
Test(Maximum_Multiple, Larger_Positives)
{
cr_assert_eq(maxMultiple(10,50), 50);
cr_assert_eq(maxMultiple(37,200), 185);
cr_assert_eq(maxMultiple(7,100), 98);
}
```