Check a given number is even or odd using function

 

Problem Statement:-  Program to Find out whether a given number is even or odd using function.


Sample Input/Output:-


Sample Input First:

13

Sample Output First: 

Given Number is odd

Sample Input Second: 

24

Sample Output Second: 

Given Number is odd.


Data requirement:-


  Input Data:- num


  Output Data:-string output


Program in C

Here is the source code of the C Program to Check a given number is even or odd using function.


Code:

#include <stdio.h>/*printf,scanf definitions */
/* This function check a given number is even or odd*/
int check_even_odd(int num)
{
    return (num % 2 == 0);
}
int main()
{
    int num;
    /* Get the number input*/
    printf("Enter the Number:");
    scanf("%d", &num);
    /* Display the given number is odd or even*/
    check_even_odd(num) ? printf("Given Number is even.") : printf("Given Number is odd.");
}


Input/Output:

Enter the Number:24

Given Number is even.


Program in C++

Here is the source code of the C++ Program to Find out whether a given number is even or odd using function.


Code:

#include <iostream>
using namespace std;
/* This Function check a given number is even or odd number.*/
int check_even_odd(int num)
{
    return (num % 2 == 0);
}
int main()
{
    int num;
    /* Get the number input*/
    cout << "Enter the Number:";
    cin >> num;
    /* Display the given number is odd or even*/
    check_even_odd(num) ? cout << "Given Number is even." : cout << "Given Number is odd.";
}


Input/Output:

Enter the Number:377

Given Number is odd.


Program in Java

Here is the source code of the Java Program to Check a given number is even or odd using function.


Code:

import java.util.Scanner;

class EvenOddCheck {
    /* This Function check a given number is even or odd number. */
    static boolean check_even_odd(int num) {
        return (num % 2 == 0);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        /* Get the number input */
        System.out.print("Enter the Number:");
        int num = sc.nextInt();
        /* Display the given number is odd or even */
        if (check_even_odd(num))
            System.out.println("Given Number is even.");
        else
            System.out.println("Given Number is odd.");
        sc.close();
    }
}


Input/Output:

Enter the Number:38

Square of Given Number is: 1444


Program in Python

Here is the source code of the Python Program to Find out whether a given number is even or odd using function.


Code:

""" This Function check a given number is even or odd number. """
def check_even_odd(num):
    return (num % 2 == 0)
""" Get the number input """
num=int(input("Enter the Number:"))
""" Display the given number is odd or even """
if (check_even_odd(num)):
    print("Given Number is even.")
else:
    print("Given Number is odd.")


Input/Output:

Enter the Number:44

Given Number is even.

Most Recommend Questions:-







More Questions:-



Post a Comment

0 Comments