
- 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
Find the Next perfect square greater than a given number in C++
Suppose we have a number n. our task is to find next perfect square number of n. So if the number n = 1000, then the next perfect square number is 1024 = 322.
To solve this, we have get the square root of the given number n, then take the floor of it, after that display the square of the (floor value + 1)
Example
#include<iostream> #include<cmath> using namespace std; int justGreaterPerfectSq(int n) { int sq_root = sqrt(n); return (sq_root + 1)*(sq_root + 1); } int main() { int n = 1000; cout << "Nearest perfect square: " << justGreaterPerfectSq(n); }
Output
Nearest perfect square: 1024
- Related Articles
- Find Elements Greater Than a Given Number In a Subarray in Java
- Check if given number is perfect square in Python
- 8086 program to find the square root of a perfect square root number
- Python Program to find out the number of sets greater than a given value
- Find the next lowest number higher than a certain number in MySQL?
- Next greater Number than N with the same quantity of digits A and B in C++
- Find the greatest five-digit number, which is a perfect square.
- Find the greatest four digit number which is a perfect square.
- Find the smallest number by which 396 must be divided to obtain a perfect square. Also find the square root of the perfect square so obtained.
- Find the smallest number by which 5103 can be divided to get a perfect square. Also find the square root of the perfect square so obtained.
- Find the smallest number by which the given number must be divided so that it becomes a perfect square: $3200$.
- Python - Find words greater than given length
- Find the smallest number by which the given number must be multiplied so that the product become a perfect square: $605$.
- Find the smallest number by which the given number must be multiplied so that the product becomes a perfect square: 77077
- Find the least number with four digits which is a perfect square

Advertisements