Problem Statement:- Program for the subtraction of two numbers using functions.
Sample Input/Output:-
Data requirement:-
Input Data:- num1, num2
Additional Data:- minus
Output Data:-sub
Program in C
Here is the source code of the C Program for the subtraction of two numbers using functions.
Code:
#include <stdio.h>/*printf,scanf definitions *//* This function calculating subtraction of two numbers. */int subtraction_two_numbers(int num1, int num2){    /*Calculating the subtraction of two numbers    and store into minus variables */    int minus = num1-num2;    return minus;}int main(){    int num1, num2;    /* Get the input of two variables */    printf("Enter the Two Numbers:");    scanf("%d%d", &num1, &num2);    /* Call Function subtraction_two_numbers with two Parameters*/    int sub = subtraction_two_numbers(num1, num2);    /* Display subtraction of two numbers*/    printf("Subtraction of two Numbers is: %d", sub);}
Input/Output:
Enter the Two Numbers:8 4
Subtraction of two Numbers is: 4
#include <stdio.h>/*printf,scanf definitions *//* This function calculating subtraction of two numbers. */int subtraction_two_numbers(int num1, int num2){    /*Calculating the subtraction of two numbers    and store into minus variables */    int minus = num1-num2;    return minus;}int main(){    int num1, num2;    /* Get the input of two variables */    printf("Enter the Two Numbers:");    scanf("%d%d", &num1, &num2);    /* Call Function subtraction_two_numbers with two Parameters*/    int sub = subtraction_two_numbers(num1, num2);    /* Display subtraction of two numbers*/    printf("Subtraction of two Numbers is: %d", sub);}
Program in C++
Here is the source code of the C++ Program to subtract two numbers using functions.
Code:
#include <iostream>using namespace std;/* This function calculating subtraction of two numbers. */int SubtractionOfTwoNumbers(int num1, int num2){    /*Calculating the subtraction of two numbers    and store into minus variables */    int minus = num1 - num2;    return minus;}int main(){    int num1, num2;    /* Get the input of two variables */    cout << "Enter the Two Numbers:";    cin >> num1 >> num2;    /* Call Function subtraction_two_numbers with two Parameters*/    int sub = SubtractionOfTwoNumbers(num1, num2);    /* Display subtraction of two numbers*/    cout << "Subtraction of two Numbers is: " << sub;}
#include <iostream>using namespace std;/* This function calculating subtraction of two numbers. */int SubtractionOfTwoNumbers(int num1, int num2){    /*Calculating the subtraction of two numbers    and store into minus variables */    int minus = num1 - num2;    return minus;}int main(){    int num1, num2;    /* Get the input of two variables */    cout << "Enter the Two Numbers:";    cin >> num1 >> num2;    /* Call Function subtraction_two_numbers with two Parameters*/    int sub = SubtractionOfTwoNumbers(num1, num2);    /* Display subtraction of two numbers*/    cout << "Subtraction of two Numbers is: " << sub;}
Input/Output:
Enter the Two Numbers:50 200
Subtraction of two Numbers is: -150
Program in Java
Here is the source code of the Java Program for the subtraction of two numbers using functions.
Code:
import java.util.Scanner;
public class SubtractionOfTwoNumbers {    /* This function calculating subtraction of two numbers. */    static int subTwoNumbers(int num1, int num2) {        /*         * Calculating the subtraction of two numbers and store into minus variables         */        int minus = num1 - num2;        return minus;    }
    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int num1, num2;        /* Get the input of two variables */        System.out.print("Enter the Two Numbers:");        num1 = sc.nextInt();        num2 = sc.nextInt();        /* Call Function subtraction_two_numbers with two Parameters */        int sub = subTwoNumbers(num1, num2);        /* Display subtraction of two numbers */        System.out.println("Subtraction of two Numbers is: " + sub);        sc.close();
    }}
Input/Output:
Enter the Two Numbers:356 989
Subtraction of two Numbers is: -633
import java.util.Scanner;
public class SubtractionOfTwoNumbers {    /* This function calculating subtraction of two numbers. */    static int subTwoNumbers(int num1, int num2) {        /*         * Calculating the subtraction of two numbers and store into minus variables         */        int minus = num1 - num2;        return minus;    }
    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int num1, num2;        /* Get the input of two variables */        System.out.print("Enter the Two Numbers:");        num1 = sc.nextInt();        num2 = sc.nextInt();        /* Call Function subtraction_two_numbers with two Parameters */        int sub = subTwoNumbers(num1, num2);        /* Display subtraction of two numbers */        System.out.println("Subtraction of two Numbers is: " + sub);        sc.close();
    }}
Program in Python
Here is the source code of the Python Program to subtract two numbers using functions.
Code:
""" This function calculating subtraction of two numbers. """
def subtraction_two_numbers(num1, num2):    """ Calculating the subtraction of two numbers """    return num1 - num2
""" Get the input of two variables """print("Enter the Two Numbers:")num1 = int(input())num2 = int(input())""" Call Function subtraction_two_numbers with two Parameters """sub = subtraction_two_numbers(num1, num2)""" Display subtraction of two numbers """print("Subtraction of two Numbers is: ", sub)
Input/Output:
Enter the Two Numbers:
5000
2000
Subtraction of two Numbers is:  3000
""" This function calculating subtraction of two numbers. """
def subtraction_two_numbers(num1, num2):    """ Calculating the subtraction of two numbers """    return num1 - num2
""" Get the input of two variables """print("Enter the Two Numbers:")num1 = int(input())num2 = int(input())""" Call Function subtraction_two_numbers with two Parameters """sub = subtraction_two_numbers(num1, num2)""" Display subtraction of two numbers """print("Subtraction of two Numbers is: ", sub)

0 Comments
Please do not Enter any spam link in the comment box