Check perfect square using addition / subtraction | C # program to check if n is perfect square or not ; This function returns true if n is perfect square , else false ; sum is sum of all odd numbers . i is used one by one hold odd numbers ; Driver Code
using System ; public class GFG { static bool isPerfectSquare ( int n ) { for ( int sum = 0 , i = 1 ; sum < n ; i += 2 ) { sum += i ; if ( sum == n ) return true ; } return false ; } public static void Main ( String [ ] args ) { if ( isPerfectSquare ( 35 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; if ( isPerfectSquare ( 49 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }