Program to check a number is even or odd

C Program

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

C++ Program

#include<iostream>
using namespace std;
int main() {
int n;
cout << "Enter any number: ";
cin >> n;
if(n % 2 == 0) {
cout << n << " is even";
} else {
cout << n << " is odd";
}
return 0;
}

Java Program

import java.util.Scanner;
class CheckEvenOdd {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter any number: ");
int n = sc.nextInt();
if (n%2 == 0) {
System.out.println(n+" is even");
} else {
System.out.println(n+" is odd");
}
}
}

Go Lang

package main
import "fmt"
func main() {
var n int
fmt.Print("Enter any number: ")
fmt.Scan(&n)
if n % 2 == 0 {
fmt.Println(n,"is even")
} else {
fmt.Println(n,"is odd");
}

PHP

<?php
if(isset($_POST['sub'])) {
$n = $_POST['n'];
if ($n %2 == 0) {
echo $n." is even";
} else {
echo $n." is odd";
}
}
?> 

Comments

Popular posts from this blog

String in golang

Inline V/S Block Level Element

Floating point Data types in Go lang

Escape Sequence | Formatted Printing | Interview Questions

Sum of two numbers

Operators in C Language| Part-4

Printing in C programming

Arrays in C Language

Program to check a year is leap year or not.

Data types in Java