Program to Check if Given Number is Positive
- Write a program to Check if Given Number is Positive in C
- Write a program to Check if Given Number is Positive in C++
- Write a program to Check if Given Number is Positive in Python
- Write a program to Check if Given Number is Positive in PHP
- Write a program to Check if Given Number is Positive in Java
- Write a program to Check if Given Number is Positive in Java Script
- Write a program to Check if Given Number is Positive in C#
Explanation:
To check if a given number is positive, the program compares the number with 0:
- If the number is greater than 0, it is positive.
- If the number is equal to 0, it is neither positive nor negative.
- If the number is less than 0, it is negative.
General Algorithm
- Take the input number.
- Compare the number:
- If number > 0, it is positive.
- If number == 0, it is neither positive nor negative.
- If number < 0, it is negative.
- Display the result
Program to Check if Given Number is Positive
-
C
-
C++
-
Python
-
PHP
-
JAVA
-
Java Script
-
C#
#include <stdio.h> int main() { int number; // Input the number printf("Enter a number: "); scanf("%d", &number); // Check if the number is positive if (number > 0) { printf("The number is positive.\n"); } else { printf("The number is not positive.\n"); } return 0; }
#include <iostream> using namespace std; int main() { int number; // Input the number cout << "Enter a number: "; cin >> number; // Check if the number is positive if (number > 0) { cout << "The number is positive." << endl; } else { cout << "The number is not positive." << endl; } return 0; }
number = int(input("Enter a number: ")) # Check if the number is positive if number > 0: print("The number is positive.") else: print("The number is not positive.")
<?php // Input the number $number = (int)readline("Enter a number: "); // Check if the number is positive if ($number > 0) { echo "The number is positive.\n"; } else { echo "The number is not positive.\n"; } ?>
import java.util.Scanner; public class PositiveNumberCheck { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Input the number System.out.print("Enter a number: "); int number = scanner.nextInt(); // Check if the number is positive if (number > 0) { System.out.println("The number is positive."); } else { System.out.println("The number is not positive."); } scanner.close(); } }
let number = parseInt(prompt("Enter a number: ")); // Check if the number is positive if (number > 0) { console.log("The number is positive."); } else { console.log("The number is not positive."); }
using System; class Program { static void Main() { // Input the number Console.Write("Enter a number: "); int number = Convert.ToInt32(Console.ReadLine()); // Check if the number is positive if (number > 0) { Console.WriteLine("The number is positive."); } else { Console.WriteLine("The number is not positive."); } } }