C++ Program which tell whether a number is zero or not without using comparator operator

ad+1

In this program we will find that input value from user is zero or not, without using comparator operator. For this purpose we will user if-else conditional statement. If user if enter zero then zero will go inside if, and we all know that if statement doesn't work on zero, so else condition will become true and it will be executed.

 Program:

// Program By http://solutionscpp.blogspot.com
// Author Mansoor Ahmed
// GMail ID: secguy000@gmail.com

 
#include<iostream>
using namespace std;

int main()
{
    int n=0;
   
    cout<<"Enter Number: ";
    cin>>n;
   
    if(n)
    {
        cout<<"Number is non-zero";
    }
   
    else
    cout<<"Number is Zero";
}

Output:

2 comments: Leave Your Comments