create a program to check whether it is positive number or negative number write the codes
Answers
Answer:
If number is less than zero, then it is a negative integer. 3. Else if number is greater than zero, then it is a positive integer.
c++
#include<iostream>
using namespace std;
int main ()
{
int num;
cout << "Enter the number to be checked : ";
cin >> num;
if (num >= 0)
cout << num << " is a positive number.";
else
cout << num << " is a negative number.";
return 0;
}
Explanation:
in C language
#include <stdio.h>
int main()
{
int A;
printf("Enter the number A: ");
scanf("%d", &A);
if (A > 0)
printf("%d is positive.", A);
else if (A < 0)
printf("%d is negative.", A);
else if (A == 0)
printf("%d is zero.", A);
return 0;
}
in C++ language
#include<iostream>
using namespace std;
int main ()
{
int num;
cout << "Enter the number to be checked : ";
cin >> num;
if (num >= 0)
cout << num << " is a positive number.";
else
cout << num << " is a negative number.";
return 0;
}