
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- 8086 program to find the square root of a perfect square root number
- Check if given number is perfect square in Python
- Find minimum number to be divided to make a number a perfect square in C++
- Next greater Number than N with the same quantity of digits A and B in C++
- Find the next lowest number higher than a certain number in MySQL?
- Python - Find words greater than given length
- Python Program to find out the number of sets greater than a given value
- Check if a number is perfect square without finding square root in C++
- Find next greater number with same set of digits in C++
- Find next Smaller of next Greater in an array in C++
- C program to find if the given number is perfect number or not
- Elements greater than the previous and next element in an Array in C++
- Find the number of elements greater than k in a sorted array using C++
- Next Greater Element in C++
- Number of nodes greater than a given value in n-ary tree in C++
Advertisements