Given integers **x** and **y** which denotes the average temperature of the week except for days **Day1** and **Day2** respectively, and the sum of the temperature of **Day1** and **Day2** as **S**, the task is to find the temperature of the days **Day1** and **Day2**.**Examples:**

Input:x = 15, y = 10, S = 50Output:Day1 = 10, Day2 = 40Explanation:

The average of week excluding Day1 is 15, the average of week excluding Day2 is 10 and the sum of temperature of Day1 and Day2 is 50. Individual temperature of the two days are 10 and 40 respecticvely.Input:x = 5, y = 10, s = 40Output:Day1 = 35, Day2 = 5Explanation:

The average of week excluding Day1 is 5, the average of week excluding Day2 is 10 and the sum of temperature of Day1 and Day2 is 40. Individual temperature of the two days are 35 and 5 respecticvely.

**Approach:** We know that** Average = sum of all observation / total number of observation.** Hence, the sum of observation = Average * number of observation i.e., **S = A * n**

So after excluding Day1 or Day2 we are left with only 6 days

so N = 6 and the equations are:

and

on subtracting the above two equations we get,

(Equation 1)

and it is given in the problem statement that

(Equation 2)

Solving the above two equations, the value of Day1 and Day2 is given by:

[Tex]Day1 = S – Day2 [/Tex]

Below is the implementation of above approach:

`// C++ program for the above approach ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; `
` ` `// Function for finding the temperature ` `void` `findTemperature(` `int` `x, ` `int` `y, ` `int` `s) `
`{ ` ` ` `double` `Day1, Day2; `
` ` ` ` `// Store Day1 - Day2 in diff `
` ` `double` `diff = (x - y) * 6; `
` ` ` ` `Day2 = (diff + s) / 2; `
` ` ` ` `// Remaining from s will be Day1 `
` ` `Day1 = s - Day2; `
` ` ` ` `// Print Day1 and Day2 `
` ` `cout << ` `"Day1 : "` `<< Day1 << endl; `
` ` `cout << ` `"Day2 : "` `<< Day2 << endl; `
`} ` ` ` `// Driver Code ` `int` `main() `
`{ ` ` ` `int` `x = 5, y = 10, s = 40; `
` ` ` ` `// Functions `
` ` `findTemperature(x, y, s); `
` ` ` ` `return` `0; `
`} ` |

*chevron_right*

*filter_none*

`// Java program for the above approach ` `class` `GFG{ `
` ` `// Function for finding the temperature ` `static` `void` `findTemperature(` `int` `x, ` `int` `y, ` `int` `s) `
`{ ` ` ` `double` `Day1, Day2; `
` ` ` ` `// Store Day1 - Day2 in diff `
` ` `double` `diff = (x - y) * ` `6` `; `
` ` ` ` `Day2 = (diff + s) / ` `2` `; `
` ` ` ` `// Remaining from s will be Day1 `
` ` `Day1 = s - Day2; `
` ` ` ` `// Print Day1 and Day2 `
` ` `System.out.println( ` `"Day1 : "` `+ Day1); `
` ` `System.out.println( ` `"Day2 : "` `+ Day2); `
`} ` ` ` `// Driver Code ` `public` `static` `void` `main(String[] args) `
`{ ` ` ` `int` `x = ` `5` `, y = ` `10` `, s = ` `40` `; `
` ` ` ` `// Functions `
` ` `findTemperature(x, y, s); `
`} ` `} ` ` ` `// This code is contributed by rock_cool` |

*chevron_right*

*filter_none*

`# Python3 program for the above approach ` ` ` `# Function for finding the temperature ` `def` `findTemperature(x, y, s): `
` ` ` ` `# Store Day1 - Day2 in diff `
` ` `diff ` `=` `(x ` `-` `y) ` `*` `6`
` ` `Day2 ` `=` `(diff ` `+` `s) ` `/` `/` `2`
` ` ` ` `# Remaining from s will be Day1 `
` ` `Day1 ` `=` `s ` `-` `Day2 `
` ` ` ` `# Print Day1 and Day2 `
` ` `print` `(` `"Day1 : "` `, Day1) `
` ` `print` `(` `"Day2 : "` `, Day2) `
` ` `# Driver Code ` `if` `__name__ ` `=` `=` `'__main__'` `: `
` ` `x ` `=` `5`
` ` `y ` `=` `10`
` ` `s ` `=` `40`
` ` ` ` `# Functions `
` ` `findTemperature(x, y, s) `
` ` `# This code is contributed by Mohit Kumar` |

*chevron_right*

*filter_none*

`// C# program for the above approach ` `using` `System; `
`class` `GFG{ `
` ` `// Function for finding the temperature ` `static` `void` `findTemperature(` `int` `x, ` `int` `y, ` `int` `s) `
`{ ` ` ` `double` `Day1, Day2; `
` ` ` ` `// Store Day1 - Day2 in diff `
` ` `double` `diff = (x - y) * 6; `
` ` ` ` `Day2 = (diff + s) / 2; `
` ` ` ` `// Remaining from s will be Day1 `
` ` `Day1 = s - Day2; `
` ` ` ` `// Print Day1 and Day2 `
` ` `Console.Write( ` `"Day1 : "` `+ Day1 + ` `'\n'` `); `
` ` `Console.WriteLine( ` `"Day2 : "` `+ Day2 + ` `'\n'` `); `
`} ` ` ` `// Driver Code ` `public` `static` `void` `Main(` `string` `[] args) `
`{ ` ` ` `int` `x = 5, y = 10, s = 40; `
` ` ` ` `// Functions `
` ` `findTemperature(x, y, s); `
`} ` `} ` ` ` `// This code is contributed by Ritik Bansal` |

*chevron_right*

*filter_none*

**Output:**

Day1 : 35 Day2 : 5

**Time Complexity:** *O(1)* **Auxiliary Space:** *O(1)*

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Count of days remaining for the next day with higher temperature
- Total number of days taken to complete the task if after certain days one person leaves
- Convert a given temperature to another system based on given boiling and freezing points
- Find the day of the week after K days from the given day
- Find number of days between two given dates
- Date after adding given number of days to the given date
- Puzzle 23 | (Days of month using 2 dice)
- Finding number of days between two dates using StringStream
- Program to calculate the number of odd days in given number of years
- Find the average of k digits from the beginning and l digits from the end of the given number
- Find the repeating and the missing number using two equations
- Find average of two numbers using bit operation
- Find the deleted value from the array when average of original elements is given
- Find n-variables from n sum equations with one missing
- C program to print number of days in a month
- Maximize number of days for which P chocolates can be distributed consecutively to N people
- Find the missing digit x from the given expression
- Find the missing value from the given equation a + b = c
- Find the last two missing digits of the given phone number
- Find all missing numbers from a given sorted array

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.