 ### Program to find whether a number is positive or negative ### Select Articles

Program to find whether a number is positive or negative

Program to find whether a number is positive or negative is discussed here. Given a number as input, find whether the number is positive or negative.

DESCRIPTION

If the number is greater than 0, print "Positive".

If the number is less than zero, print "Negative"

Input & Output format:

Input consist of 1 integer.

Sample Input and Output 1:

56

Positive

Sample Input and Output 2:

-56

Negative

Algorithm to find whether a number is positive or negative

Input the number.

If(num > 0)

Print "Positive"

Else

Print "Negative"

Program to find whether a number is positive or negative

C

// C Program to find whether an integer is positive or negative

#include

int main()

{

//Fill the code

int num;

scanf(“%d”,#);

if(num > 0)

printf(“Positive”);

else

printf(“Negative”);

return 0;

}

C++

// C++ program to find whether an integer is positive or negative

#include

using namespace std;

int main()

{

//Fill the code

int num;

cin >> num;

if(num > 0)

cout << “Positive”;

else

cout << “Negative”;

return 0;

}

JAVA 8

import java.util.*;

public class Main

{

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

int num;

num = sc.nextInt();

if(num > 0)

System.out.print(“Positive”);

else

{

System.out.print(“Negative”);

}

}

}

PYTHON 3

# Python program to find whether an integer is positive or negative

num = int(input())

if(num > 0):

print(“Positive”)

else:

print(“Negative”)

OUTPUT

44

Positive

Program to find whether a number is positive or negative using ternary operator

C

// C program to find whether a number is positive or negative

#include

int main()

{

//Fill the code

int num;

scanf(“%d”,#);

num > 0? printf(“Positive”) : printf(“Negative”);

return 0;

}

C+

// C++ program to find whether a number is positive or negative

#include

using namespace std;

int main()

{

//Fill the code

int num;

cin >> num;

num > 0? cout << “Positive” : cout << “Negative”;

return 0;

}

OUTPUT

44

Positive