Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check Whether Three Numbers Form a Geometric Progression

Basic Acceptance 82.80% Points 10.00

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

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

Example 2

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

Example 3

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

Constraints
  • -10? = a, b, c = 10?
  • a ? 0, b ? 0, c ? 0
Companies
Microsoft Apple
Topics
Data Structures Basics Comparisons
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions