Showing posts with label Positive or negative number. Show all posts
Showing posts with label Positive or negative number. Show all posts

Tuesday, 13 January 2015

Cpp Program to find whether a number is positive or negative

This is a basic Cpp Program which checks whether a number is positive or negative.

A number is said to be POSITIVE if it is greater than 0 , NEGATIVE if less than 0.

PROGRAM:
#include <iostream>

using namespace std;

int main()
{
    int n;
    cout << "Enter any number : \t" << endl;
    cin  >> n ;

    if(n == 0 )
        cout << n << " is neither POSITIVE  nor NEGATIVE" << endl;

    else if( n > 1){
        cout << n << " is POSITIVE  number" << endl;
    }
    else
        cout << n << " is NEGATIVE  number" << endl;
    return 0;
}


OUTPUT :
Cpp - Positive or Negative
Cpp - Positive or Negative
Cpp - Positive or Negative

Monday, 5 January 2015

Java Program to check whether a number is Positive Or Negative


This is a simple basic program which checks whether the number is positive or negative.


PROGRAM :


package codingcorner.in;

import java.util.Scanner;

public class PositiveOrNegative {
 public static void main(String[] args) {
  float a;
  Scanner scan = new Scanner(System.in);

  System.out.println("Enter any number :\n");
  a = scan.nextFloat();

  scan.close();

  if (a == 0)
   System.out.println(a + " is neither positive nor negative");
  else if (a > 0)
   System.out.println(a + " is a Positive number");
  else
   System.out.println(a + " is a Negative number");
 }
}
 
OUTPUT :