Number of ways to obtain each numbers in range [ 1 , b + c ] by adding any two numbers in range [ a , b ] and [ b , c ] | Java program to calculate the number of ways ; Initialising the array with zeros . You can do using memset too . ; Printing the array ; Driver code
class GFG { public static void CountWays ( int a , int b , int c ) { int x = b + c + 1 ; int [ ] arr = new int [ x ] ; for ( int i = a ; i <= b ; i ++ ) { for ( int j = b ; j <= c ; j ++ ) { arr [ i + j ] ++ ; } } for ( int i = 1 ; i < x ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int a = 1 ; int b = 2 ; int c = 2 ; CountWays ( a , b , c ) ; } }