Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check Whether Three Numbers Form a Geometric Progression

Basic Acceptance 82.8% Points 10

You are given three non-zero numbers. Your task is to determine whether they form a geometric progression (GP), meaning the ratio between consecutive terms is constant.

Print Yes if the numbers form a geometric progression; otherwise, print No.

Examples
Example 1

image Input: a = 2, b = 4, c = 8
Output: Yes
Explanation: The common ratio is 2 throughout.

Example 2

image Input: a = 2, b = 6, c = 12
Output: No
Explanation: The ratios 3 and 2 are not equal.

Example 3

image Input: a = 3, b = 3, c = 3
Output: Yes
Explanation: A constant sequence has a common ratio of 1.

Constraints
  • -109 <= each number <= 109
  • No number is 0.
Topics
Data Structures Basics Comparisons
Companies
Microsoft Apple
Added 31 Oct 2026 82.8% acceptance
Ln 1, Col 1Sign in to save your code
2 4 8
Yes