Program to check a number is positive, negative or zero

C Program

#include<stdio.h>
int main() {
int n;
printf("Enter any number: ");
scanf("%d",&n);
if( n > 0) {
printf("%d is positive",n);
}
if (n < 0) {
printf("%d is negative",n);
}
if (n == 0) {
printf("%d is zero",n);
}
return 0;
}

C++ Program

#include<iostream>
using namespace std;
int main() {
int n;
cout << "Enter any number: ";
cin >> n;
if( n > 0) {
cout << n << " is positive";
}
if (n < 0) {
cout << n << " is negative";
}
if (n == 0) {
cout << n << " is zero";
}
return 0;
}

Java Program

import java.util.Scanner;
class CheckPositiveNegative {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter any number: ");
int n = sc.nextInt();
if(n > 0) {
System.out.println(n+" is a positive number");
}
if(n < 0) {
System.out.println(n+" is a negative number");
}
if(n == 0) {
System.out.println(n+" is zero");
}
}
}

Go Lang

package main
import "fmt"
func main() {
var n int 
        fmt.Print("Enter any number: ")
fmt.Scan(&n)
if n > 0 {
fmt.Println(n,"is positive");
}
if(n < 0) {
fmt.Println(n,"is negative");
}
if(n == 0) {
fmt.Println(n,"is zero");
}

PHP program

<?php
if(isset($_POST['sub'])) {
$n = $_POST['n'];
if ($n > 0) {
echo $n." is positive";
}
if ($n < 0) {
echo $n." is negative";
}
if ($n == 0) {
echo $n." is zero";
}
}
?> 

Comments

Popular posts from this blog

Overview of Go lang

Arrays in C Language

Data Types in Go language

Creating your first html page

Say Hello world in Go lang

Arrays in Go lang

Installing go lang

String in golang

Decision Making in Go lang

Decision Making Statements