Check whether product of integers from a to b is positive , negative or zero | C ++ implementation of the approach ; Function to check whether the product of integers of the range [ a , b ] is positive , negative or zero ; If both a and b are positive then the product will be positive ; If a is negative and b is positive then the product will be zero ; If both a and b are negative then we have to find the count of integers in the range ; Total integers in the range ; If n is even then the resultant product is positive ; If n is odd then the resultant product is negative ; Driver code
#include <iostream> NEW_LINE using namespace std ; void solve ( long long int a , long long int b ) { if ( a > 0 && b > 0 ) { cout << " Positive " ; } else if ( a <= 0 && b >= 0 ) { cout << " Zero " << endl ; } else { long long int n = abs ( a - b ) + 1 ; if ( n % 2 == 0 ) { cout << " Positive " << endl ; } else { cout << " Negative " << endl ; } } } int main ( ) { int a = -10 , b = -2 ; solve ( a , b ) ; return 0 ; }