WAP in C++ to input any number and to print whether the number is positive, negative or zero.
➡️ Wrong Answer will be reported
Answers
Answered by
37
Given:
- WAP in C++ to input any number and to print whether the number is positive, negative or zero.
________________________
Logic Used:-
If n<0 Number is Negative .
if n>0 Number is positive.
else Number is 0.
________________________
Code:
- #include<iostream>
- using namespace std;
- int main ()
- {
- int n;
- cout << "Enter the number to be checked :";
- cin >> num;
- if (num > 0)
- cout << num << " is a positive number.";
- else if(num<0)
- cout << num << " is a negative number.";
- else
- cout << num << " is a Zero";
- return 0;
- }
________________________
Test 1→
Input:
Enter the number to be checked
46
Output:
46 is a positive number
Test 2→
Input:
Enter the number to be checked
-46
Output:
-46 is a negative number
Similar questions