
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ code to find screen size with n pixels
Suppose we have a number n. In a display there will be n pixels. We have to find the size of rectangular display. The rule is like below −
The number of rows (a) does not exceed number of columns (b) [a <= b]
The difference between b - a is as minimum as possible
So, if the input is like n = 12, then the output will be (3, 4)
Steps
To solve this, we will follow these steps −
i := square root of n while n mod i is non-zero, do: (decrease i by 1) return (i, n / i)
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; void solve(int n){ int i = sqrt(n); while (n % i) i--; cout << i << ", " << n / i; } int main(){ int n = 12; solve(n); }
Input
12
Output
3, 4
- Related Articles
- How to define a measurement in screen pixels with CSS?
- Set Font Size with Pixels using CSS
- Setting Font Size with Pixels using CSS
- Setting Font Size with Pixels in CSS
- How to get screen dimensions in pixels in Android app?
- Determine Matplotlib axis size in pixels
- How to get screen dimensions in pixels on Android App using Kotlin?
- Hide content depending on screen size with Bootstrap
- How to change cell size to inches/cm/mm/pixels in Excel?
- How to support different screen size in Android?
- How to get the screen size in Tkinter?
- Turn transparent pixels to a specified color and make opaque pixels transparent with CSS
- C++ code to find tree height after n days
- C++ code to find minimum different digits to represent n
- How to detect the screen size of iPhone 5?

Advertisements