Program to find whether a number is positive or negative | faceprep

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 Program to find whether an integer is positive or negative

#include
int main()
{
//Fill the code
int num;
scanf(“%d”,&num);
if(num > 0)
printf(“Positive”);
else
printf(“Negative”);
return 0;
}

// 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 program to find whether an integer is positive or negative

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 program to find whether an integer is positive or negative

num = int(input())
if(num > 0):
print(“Positive”)
else:
print(“Negative”)

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

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

#include<stdio.h>

int main()
{
//Fill the code
int num;
scanf(“%d”,&num);
num > 0? printf(“Positive”) : printf(“Negative”);
return 0;
}

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

#include<iostream>
using namespace std;

int main()
{
//Fill the code
int num;
cin >> num;
num > 0? cout << “Positive” : cout << “Negative”;
return 0;
}

Output:

find whether a number is positive or negative