How to check a number is Even or Odd in C, Java and C#


Program for Check a Number is Even or Odd :-

Program for C :-

#include<stdio.h>
#include<conio.h>
void main()
{
int num;
printf("Enter a Number \n");
scanf("%d",&num);
if(num%2==0)
printf("Number is Even");
else
printf("Number is Odd");
getch();
}

Program in Java :-

public class TestNumber
{
public sttaic void main(String args[])
{
int num;
System.out.println("Enter a Number");
Console con=System.console(System.in);
num=Integer.parseInt(con.readLine());
if(num%2==0)
System.out.println("Number is Even");
else
System.out.println("Number is Odd");
}
}


Program in C# :-

public class Test
{
public static void Main()
{
int num;
Console.WriteLine("Enter a Number");
num=Integer.Parse(Console.ReadLine());
if(num%2==0)
Console.WriteLine("Number is Even");
else
Console.WriteLine("Number is Odd");
}
}


{ 0 comments... read them below or add one }

Post a Comment