Problem Statement:- Program to Find out whether a given number is even or odd using function.
Sample Input/Output:-
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.
#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.");}
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.";}
#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
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(); }}
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.
""" 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.")
0 Comments
Please do not Enter any spam link in the comment box