General Statement:

A relatively simple task for humans to do is to identify the next number in an arithmetic sequence of numbers. For example, given the sequence of numbers 3, 6, and 9, we know that the next number in the sequence is 12 since each number is followed by a number increasing it by 3. Alternatively, given the sequence of numbers 3, 6, and 12, we know that the next number in the sequence is 24 since each number is followed by a number that doubles it.

Your task is to write a program that will deduce the next integer in a given sequence of three integers where the same arithmetic operation is applied to each integer to produce the next. The only arithmetic operations that will be used are addition, subtraction, multiplication, or division.

Input: The first line of the input contains an integer n that represents the number of data collections that follow where each data collection is on a single line. Each input line contains three integers with each pair of integers separated by a single space. The integers represent a sequence as described in the General Statement.

Output: Your program should produce n lines of output (one for each data collection). The output for each data collection should be the next integer in the corresponding input sequence.

The output is to be formatted exactly like that for the sample output given below.

Assumptions: The value of n will be between 1 and 100, inclusive.

There will be exactly one answer to each input sequence.

The answer will always be an integer (even if division is used).

Sample Input:

3

7 21 35

-10 20 -40

64 16 4

Sample Output:

49

80

1

#include <stdio.h>
int main ()
{
int n;
scanf ("%d", &n);
while ( n-- ) {
double x, y, z;
scanf ("%lf %lf %lf", &x, &y, &z);
if ( y - x == z - y )
printf ("%0.lf\n", z + y - x);
else
printf ("%0.lf\n", z / (x / y));
}
return 0;
}

### Like this:

Like Loading...

*Related*

you are having a laugh with that program

according to your program:

test input: 9 10 15

output:17

test input: 3 0 5

output: 0