Subscribe Us

Responsive Advertisement

Advertisement

Exception Handling Final Example divide N by M (division)

 




#include<bits/stdc++.h>

using namespace std;

void divide(int nm,int di)

{

    try

    {

        if(di==0)throw 0;

        cout<<(double)((double)nm/di)<<endl;

    }

    catch(...)

    {

        cout<<"can't divide by zero\n";

    }

}

int main()

{

    int n,d;

   for(int i=1;i<=3;i++)

    {

         cin>>n>>d;

         divide(n,d);

    }


    return 0;


}


Post a Comment

0 Comments