Program to print non square numbers | CPP program to print first n non - square numbers . ; Function to check perfect square ; function to print all non square number ; variable which stores the count ; not perfect square ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPerfectSquare ( int n ) { if ( n < 0 ) return false ; int root = round ( sqrt ( n ) ) ) ; return n == root * root ; } void printnonsquare ( int n ) { int count = 0 ; for ( int i = 1 ; count < n ; ++ i ) { if ( ! isPerfectSquare ( i ) ) { cout << i << " ▁ " ; count ++ ; } } } int main ( ) { int n = 10 ; printnonsquare ( n ) ; return 0 ; }