# Program to find the head start in a race

Given the head start that A gives to B and C in a 100-meters race. The task is to find the head-start that B can give to C in the same race.

**Examples:**

Input: B = 10 meters, C = 28 meters Output: 20 meters B can give C a start of 20 meters. Input: B = 20 meters, C = 50 meters Output: 62 meters B can give C a start of 62 meters.

**Approach:**

Total meters in a race = 100 meters.

A is ahead of B by 10 meters. When A completed it’s 100 meters B completed it’s 90 meters.

Similarly, A is ahead of C by 28 meters. When A completed it’s 100 meters C completed it’s 72 meters.

Now, When B completed it’s 90 meters C completed it’s 72 meters.

So when B completed it’s 100 meters C completed it’s 80 meters.

–> (( C * 100) / B)

–> (( 72 * 100) / 90) i.e80 meters

So B can give C a start of 20 meters

Below is the implementation of the above approach:

## C++

`// C++ implementation of above approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the B start to C ` `int` `Race(` `int` `B, ` `int` `C) ` `{ ` ` ` `int` `result = 0; ` ` ` ` ` `// When B completed it's 100 meter ` ` ` `// then Completed meters by C is ` ` ` `result = ((C * 100) / B); ` ` ` ` ` `return` `100 - result; ` `} ` ` ` `// Driver Code. ` `int` `main() ` `{ ` ` ` `int` `B = 10, C = 28; ` ` ` ` ` `// When A completed it's 100 meter ` ` ` `// Then completed meters of B and C is ` ` ` `B = 100 - B; ` ` ` `C = 100 - C; ` ` ` ` ` `cout << Race(B, C) << ` `" meters"` `; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of above approach ` `public` `class` `GFG ` `{ ` ` ` `// Function to find the B start to C ` `static` `int` `Race(` `int` `B, ` `int` `C) ` `{ ` ` ` `int` `result = ` `0` `; ` ` ` ` ` `// When B completed it's 100 meter ` ` ` `// then Completed meters by C is ` ` ` `result = ((C * ` `100` `) / B); ` ` ` ` ` `return` `100` `- result; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `B = ` `10` `; ` ` ` `int` `C = ` `28` `; ` ` ` ` ` `// When A completed it's 100 meter ` ` ` `// Then completed meters of B and C is ` ` ` `B = ` `100` `- B; ` ` ` `C = ` `100` `- C; ` ` ` ` ` `System.out.println(Race(B, C) + ` `" meters"` `); ` `} ` `} ` ` ` `// This code is contributed ` `// by ChitraNayal ` |

*chevron_right*

*filter_none*

## Python 3

`# Python 3 implementation ` `# of above approach ` ` ` `# Function to find the ` `# B start to C ` `def` `Race(B, C): ` ` ` ` ` `result ` `=` `0` `; ` ` ` ` ` `# When B completed it's 100 meter ` ` ` `# then Completed meters by C is ` ` ` `result ` `=` `((C ` `*` `100` `) ` `/` `/` `B) ` ` ` ` ` `return` `100` `-` `result ` ` ` `# Driver Code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` `B ` `=` `10` ` ` `C ` `=` `28` ` ` ` ` `# When A completed it's 100 meter ` ` ` `# Then completed meters of B and C is ` ` ` `B ` `=` `100` `-` `B; ` ` ` `C ` `=` `100` `-` `C; ` ` ` ` ` `print` `(` `str` `(Race(B, C)) ` `+` `" meters"` `) ` ` ` `# This code is contributed ` `# by ChitraNayal ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of above approach ` `using` `System; ` `class` `GFG ` `{ ` ` ` `// Function to find the B start to C ` `static` `int` `Race(` `int` `B, ` `int` `C) ` `{ ` ` ` `int` `result = 0; ` ` ` ` ` `// When B completed it's 100 meter ` ` ` `// then Completed meters by C is ` ` ` `result = ((C * 100) / B); ` ` ` ` ` `return` `100 - result; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `Main() ` `{ ` ` ` `int` `B = 10; ` ` ` `int` `C = 28; ` ` ` ` ` `// When A completed it's 100 meter ` ` ` `// Then completed meters of B and C is ` ` ` `B = 100 - B; ` ` ` `C = 100 - C; ` ` ` ` ` `Console.Write(Race(B, C) + ` `" meters"` `); ` `} ` `} ` ` ` `// This code is contributed ` `// by ChitraNayal ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of above approach ` ` ` `// Function to find the B start to C ` `function` `Race(` `$B` `, ` `$C` `) ` `{ ` ` ` `$result` `= 0; ` ` ` ` ` `// When B completed it's 100 meter ` ` ` `// then Completed meters by C is ` ` ` `$result` `= ((` `$C` `* 100) / ` `$B` `); ` ` ` ` ` `return` `100 - ` `$result` `; ` `} ` ` ` `// Driver Code ` `$B` `= 10; ` `$C` `= 28; ` ` ` `// When A completed it's 100 meter ` `// Then completed meters of B and C is ` `$B` `= 100 - ` `$B` `; ` `$C` `= 100 - ` `$C` `; ` ` ` `echo` `Race(` `$B` `, ` `$C` `) . ` `" meters"` `; ` ` ` `// This code is contributed ` `// by ChitraNayal ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

20 meters

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

## Recommended Posts:

- Number of sequences which has HEAD at alternate positions to the right of the first HEAD
- Aptitude | Race | Question 2
- Aptitude | Race | Question 5
- Aptitude | Race | Question 4
- Find start and ending index of an element in an unsorted array
- Count Number of animals in a zoo from given number of head and legs
- Sub-strings that start and end with one character and have at least one other
- Count of subarrays which start and end with the same element
- Slow Start Backoff Algorithm for Ad-Hoc
- Number of substrings that start with "geeks" and end with "for"
- Program to find value of 1^k + 2^k + 3^k + ... + n^k
- Program to find sum of 1 + x/2! + x^2/3! +...+x^n/(n+1)!
- Program to find the sum of the series 1 + x + x^2+ x^3+ .. + x^n
- Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!
- Program to Find the value of cos(nΘ)

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.