Here, we have a basic program example to check if a number is positive or negative using different languages. This program is created in c language, c++, Java, and Python.
Program to check if a number is positive or negative in C language.
#include <stdio.h>
void main()
{
int num;
printf("Enter a number : ");
scanf("%d", &num);
if (num > 0)
printf("The number is positive\n");
else if (num == 0)
printf("The number is zero\n");
else
printf("The number is negative\n");
}
Program to check if a number is positive or negative in C++ language.
#include<iostream>
using namespace std;
int main(){
int num;
cout<<"Enter a number : ";
cin>>num;
if (num > 0)
cout<<"The number is positive";
else if (num == 0)
cout<<"The number is zero";
else
cout<<"The number is negative";
}
Program to check if a number is positive or negative in Python language.
num = int(input("Enter a number: "))
if num > 0 :
print("The number is positive\n")
elif num == 0 :
print("The number is zero\n")
else:
print("The number is negative\n")
Program to check if a number is positive or negative in Java language.
import java.util.*;
class check
{
public static void main(String[] args)
{
int num;
Scanner s=new Scanner(System.in);
System.out.println("Enter a number :");
num = s.nextInt();
if(num > 0){
System.out.println("The number is positive");
}
else if(num == 0){
System.out.println("The number is zero");
}
else {
System.out.println("The number is negative");
}
}
}