Divide By Zero | Divide by Zero Exception in C++

Divide By Zero | Divide by Zero in C++

You have to check it yourself and toss an exception. Integer divide by zero isn't an exception in standard C++. Nor is skimming point divide by zero yet in any event that has explicit methods for managing it. what's more, you would imagine that overflow_error would be perfect for demonstrating a divide by zero.

 Divide by Zero Program

#include<iostream>
#include<stdexcept>
using namespace std;
int main()
{
   float x,y,quo;
    try
    {
     cout<<"Enter 2 numbers : ";
     cin>>x>>y;
     if(y==0) throw exception();
     quo=x/y;
     cout<<"Quotient is "<<quo<<endl;
    }
    catch(exception &e)
    {
     cout<<"Divide By Zero Error."<<endl;
    }
    return 0;
}

OUTPUT:
Enter 2 numbers: 5   0
Divide By Zero Error.


You must be also searching for these programming languages : 


tags: programs of C, Divide by Zero, zero divide by zero, Divide by Zero Exception, Error Handling in C++, tutorials point java

Post a Comment

Previous Post Next Post