Q:

Write a program in C++ to check overflow/underflow during various arithmetical operation

0

Write a program in C++ to check overflow/underflow during various arithmetical operation

Sample Output:

 Check overflow/underflow during various arithmetical operation :      
 Range of int is [-2147483648, 2147483647]                             
---------------------------------------------------------------------  
 Overflow the integer range and set in minimum range : -2147483648     
 Increasing from its minimum range : -2147483647                       
 Product is :1                                                         
 Underflow the range and set in maximum range : 2147483647             
 Decreasing from its maximum range : 2147483646                        
 Product is : 0 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;
 
int main() 
{
    cout << "\n\n Check overflow/underflow during various arithmetical operation :\n";
    cout << " Range of int is [-2147483648, 2147483647]"<< endl;
	cout << "---------------------------------------------------------------------\n";   
   int n1 = 2147483647;      // maximum range of integer
   cout <<" Overflow the integer range and set in minimum range : " << n1 + 1 << endl; 
   cout <<" Increasing from its minimum range : " << n1 + 2 << endl; 
   cout <<" Product is :" << n1 * n1 << endl; 
 
   int n2 = -2147483648;     // minimum range of integer
   cout <<" Underflow the range and set in maximum range : " << n2 - 1 << endl; 
   cout <<" Decreasing from its maximum range : " << n2 - 2 << endl; 
   cout <<" Product is : " << n2 * n2 << endl; 
   cout << endl;
   return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now