Check if a number can be expressed as a sum of consecutive numbers | C # program to check if a number can be expressed as sum of consecutive numbers ; This function returns true if n can be expressed sum of consecutive . ; We basically return true if n is a power of two ; Driver Code
using System ; class Test { static bool canBeSumofConsec ( int n ) { return ( ( ( n & ( n - 1 ) ) != 0 ) && n != 0 ) ; } public static void Main ( ) { int n = 15 ; Console . Write ( canBeSumofConsec ( n ) ? " True " : " False " ) ; } }