Check for non zero input value
Take user input as a positive, negative or zero integer value and check if it is a non zero value.
Learning Objectives
- Checking if condition by just putting the term value inside, without putting a condition or relational operator.
Source Code
|
|
Run Output
Code Understanding
if(n) cout<<“Given number is a non zero value”<<endl;
The term n itself inside if check can return true when it is a non zero term. If it is a 0 value then the condition will be false and nothing will be printed.
Notes
- This kind of usage of term itself as a true or false condition is often done with Boolean variables. Integer variables can also be used easily as in this example.
Suggested Filename(s): checknonzero.cpp
Created: 22-Dec-2017 01:32 | Updated: 15-Sep-2018 11:04|
