Problem Statement:- Program to find a minimum number from given two numbers using a user-defined function.
Sample Input/Output:-
Data requirement:-
Input Data:- num1, num2
Output Data:-min
Program in C
Here is the source code of the C Program to Find the factorial of a number using function.
Code:
#include <stdio.h>/*printf,scanf definitions *//* This function find a minimum number from given two numbers. */int minimum_of_two(int num1, int num2){ return (num1<num2) ? num1:num2;}int main(){ int num1, num2; /* Get the input of two variables */ printf("Enter the Two Numbers:"); scanf("%d%d", &num1, &num2); /* Call Function minimum_of_two with two Parameters*/ int min= minimum_of_two(num1, num2); /* Display smallest number between two numbers*/ printf("Minimum Number Between two Numbers is: %d", min);}
Input/Output:
Enter the Two Numbers:8 13
Minimum Number Between two Numbers is: 8
#include <stdio.h>/*printf,scanf definitions *//* This function find a minimum number from given two numbers. */int minimum_of_two(int num1, int num2){ return (num1<num2) ? num1:num2;}int main(){ int num1, num2; /* Get the input of two variables */ printf("Enter the Two Numbers:"); scanf("%d%d", &num1, &num2); /* Call Function minimum_of_two with two Parameters*/ int min= minimum_of_two(num1, num2); /* Display smallest number between two numbers*/ printf("Minimum Number Between two Numbers is: %d", min);}
Program in C++
Here is the source code of the C++ Program to find a minimum number from given two numbers using a user-defined function.
Code:
#include <iostream>using namespace std;/* This function find a minimum number from given two numbers. */int minimum_of_two(int num1, int num2){ return (num1 < num2) ? num1 : num2;}int main(){ int num1, num2; /* Get the input of two variables */ cout << "Enter the Two Numbers:"; cin >> num1 >> num2; /* Call Function minimum_of_two with two Parameters*/ int min = minimum_of_two(num1, num2); /* Display smallest number between two numbers*/ cout << "Minimum Number Between two Numbers is: " << min;}
#include <iostream>using namespace std;/* This function find a minimum number from given two numbers. */int minimum_of_two(int num1, int num2){ return (num1 < num2) ? num1 : num2;}int main(){ int num1, num2; /* Get the input of two variables */ cout << "Enter the Two Numbers:"; cin >> num1 >> num2; /* Call Function minimum_of_two with two Parameters*/ int min = minimum_of_two(num1, num2); /* Display smallest number between two numbers*/ cout << "Minimum Number Between two Numbers is: " << min;}
Input/Output:
Enter the Two Numbers:325 201
Minimum Number Between two Numbers is: 201
Program in Java
Here is the source code of the Java Program to Find the factorial of a number using function.
Code:
import java.util.Scanner;
public class FindMinimum { /* This function find a minimum number from given two numbers. */ static int MinimumOfTwo(int num1, int num2) { return (num1 < num2) ? num1 : num2; }
public static void main(String[] args) { Scanner sc = new Scanner(System.in); /* Get the input of two variables */ System.out.println("Enter the Two Numbers:"); int num1 = sc.nextInt(); int num2 = sc.nextInt(); /* Call Function MinimumOfTwo with two Parameters */ int min = MinimumOfTwo(num1, num2); /* Display smallest number between two numbers */ System.out.println("Minimum Number Between two Numbers is: " + min); sc.close(); }}
Input/Output:
Enter the Two Numbers:
33
20
Minimum Number Between two Numbers is: 20
import java.util.Scanner;
public class FindMinimum { /* This function find a minimum number from given two numbers. */ static int MinimumOfTwo(int num1, int num2) { return (num1 < num2) ? num1 : num2; }
public static void main(String[] args) { Scanner sc = new Scanner(System.in); /* Get the input of two variables */ System.out.println("Enter the Two Numbers:"); int num1 = sc.nextInt(); int num2 = sc.nextInt(); /* Call Function MinimumOfTwo with two Parameters */ int min = MinimumOfTwo(num1, num2); /* Display smallest number between two numbers */ System.out.println("Minimum Number Between two Numbers is: " + min); sc.close(); }}
Program in Python
Here is the source code of the Python Program to find a minimum number from given two numbers using a user-defined function.
Code:
""" This function find a minimum number from given two numbers. """
def minimum_of_two(num1, num2): if num1 < num2: return num1 else: return num2
""" Get the input of two variables """print("Enter the Two Numbers:")num1 = int(input())num2 = int(input())""" Display smallest number between two numbers """print("Minimum Number Between two Numbers is: ", minimum_of_two(num1, num2))
Input/Output:
Enter the Two Numbers:
568
933
Minimum Number Between two Numbers is: 568
""" This function find a minimum number from given two numbers. """
def minimum_of_two(num1, num2): if num1 < num2: return num1 else: return num2
""" Get the input of two variables """print("Enter the Two Numbers:")num1 = int(input())num2 = int(input())""" Display smallest number between two numbers """print("Minimum Number Between two Numbers is: ", minimum_of_two(num1, num2))
0 Comments
Please do not Enter any spam link in the comment box