Divide by zero error in C++:
Basically, sometime when we perform division operation then it may be possible that you divide some number by 0. so it is give an error and program terminate uncorrectly so this problem is called as divide by zero error i C++:
Without exception handling:
program:
#include< iostream>
int main()
{
int n=10,num;
cout<<"Enter number to divide 10"<< endl;
cin>>num;
n=n/num;
cout<< n;
}
Enter number to divide 10
0
error
#include< iostream>
int main()
{
int n=10,num;
cout<<"Enter number to divide 10"<< endl;
cin>>num;
try:
n=n/num;
cout<< n;
catch:
cout<<"Wrong operation!,It is divisible by zero";
}
Enter number to divide 10
0
Wrong operation!,It is divisible by zero