Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Check Whether Three Numbers Form an Arithmetic Progression

Basic Acceptance 73.03% Points 10

You are given three numbers. Your task is to determine whether they form an arithmetic progression (AP), meaning the difference between consecutive terms is constant.

Print Yes if the numbers form an arithmetic progression; otherwise, print No.

Examples
Example 1

Input: a = 2, b = 4, c = 6
Output: Yes
Explanation: The common difference is 2 throughout.

Example 2

Input: a = 1, b = 3, c = 6
Output: No
Explanation: The differences 2 and 3 are not equal.

Example 3

Input: a = 5, b = 5, c = 5
Output: Yes
Explanation: A constant sequence has a common difference of 0.

Constraints
  • -109 = each number = 109
Topics
Data Structures Basics
Companies
Apple Samsung Walmart DE Shaw
Added 05 Nov 2026 73.03% acceptance
Ln 1, Col 1Sign in to save your code
2 4 6
yes