# An Arithmetic Problem

A sequence is an arithmetic sequence if every two successive number has same difference. Suppose thi…

If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

My code gives correct output but when i submitted it shows wrong answer. Where is the problem?

n = int(input())
for i in range(n):
x, y, z, n = map(int, input().split())
if z - y == y - x:
cal = z - y
number = cal * n
print(“Case %d: %d” % (i+1, number))
else:
print(“Case %d: Error” % (i+1))

for input 6 7 8 2 output should be 7 not 2

@hjr265

``````#include <iostream>

using namespace std;

int main() {
int n , a , b , c , d;
cin >> n ;

for(int i = 1 ; i <= n ; i++){
cin >> a >> b >> c >> d ;
int x , y ;
x = b-a;
y = c-b;
cout <<"Case"<<" "<<i<<':'<<" ";

if(x==y)
cout << x*d<<endl;
else
cout << "Error"<<endl;
}
}
``````

what’s wrong in this code;
every time my answer is being accepted in the first test case … But on the 2nd test case , it is showing wrong answer,

Wrong Answer for 2nd test case

``````// An Arithmetic Problem
//
// Created by Abuhena Rony

#include <bits/stdc++.h>

int main()
{
int tcases;
scanf("%d", &tcases);
for (int i = 1; i <= tcases; ++i)
{
int num1, num2, num3, num;
scanf("%d %d %d %d", &num1, &num2, &num3, &num);
if (num2 - num1 == num3 - num2)
{
int gap = num2 - num1;
int element = num1;
for (int j = 2; j <= num; j++)
{
element += gap;
//                printf("%d\n",element);
if (j == num)
{
printf("Case %d: %d\n", i, element);
break;
}
}
}
else
printf("Case %d: Error\n", i);
}
return 0;
}
``````