304 North Cardinal St.
Dorchester Center, MA 02124

# Volume Control CodeChef Solution

## Problem – Volume Control CodeChef Solution

Chef is watching TV. The current volume of the TV is X. Pressing the `volume up` button of the TV remote increases the volume by 1 while pressing the `volume down` button decreases the volume by 1. Chef wants to change the volume from X to Y. Find the minimum number of button presses required to do so.

### Input Format

• The first line contains a single integer T – the number of test cases. Then the test cases follow.
• The first and only line of each test case contains two integers X and Y – the initial volume and final volume of the TV.

### Output Format

For each test case, output the minimum number of times Chef has to press a button to change the volume from X to Y.

• 1≤T≤100
• 1≤X,Y≤100

### Sample 1:

``````Input: 2
50 54
12 10
Output: 4
2``````

### Explanation:

Test Case 1: Chef can press the `volume up` button 4 times to increase the volume from 50 to 54.

Test Case 2: Chef can press the `volume down` button 2 times to decrease the volume from 12 to 10.

### Volume Control CodeChef Solution in C++14

``````#include <iostream>
using namespace std;

int main() {
int i ;
cin >> i;
while(i>0){
int a ,b;
cin >> a >>b;
int min = a - b;
if(min < 0){
min = min*(-1);
}
cout << min << endl;
i--;
}
return 0;
}
``````

### Volume Control CodeChef Solution in Java

``````import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=1;i<=n;i++)
{
int X=sc.nextInt();
int Y=sc.nextInt();
if(X>Y)
{
System.out.println(X-Y);
}
else
{
System.out.println(Y-X);
}
}
}
}
``````
##### Volume Control CodeChef Solution Review:

In our experience, we suggest you solve this Volume Control CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Volume Control CodeChef Solution

Find on CodeChef

##### Conclusion:

I hope this Volume Control CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions