text: Nth non | CPP program to find n - th non - square number . ; function to find the nth Non - Square Number ; conversion from int to long double is necessary in order to preserve decimal places after square root . ; calculating the result ; Driver code ; initializing the term number ; Print the result
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; int findNthNonSquare ( int n ) { long double x = ( long double ) n ; long double ans = x + floor ( 0.5 + sqrt ( x ) ) ; return ( int ) ans ; } int main ( ) { int n = 16 ; cout << " The ▁ " << n << " th ▁ Non - Square ▁ number ▁ is ▁ " ; cout << findNthNonSquare ( n ) ; return 0 ; }