Program to subtract two numbers using functions

Problem Statement:- Program for the subtraction of two numbers using functions.


Sample Input/Output:-


Sample Input First:

8

4

Sample Output First: 

4

Sample Input Second: 

50

200

Sample Output Second: 

-150


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 num1int num2)
{
    /*Calculating the subtraction of two numbers
    and store into minus variables */
    int minus = num1-num2;
    return minus;
}
int main()
{
    int num1num2;
    /* 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(num1num2);
    /* 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


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 num1int 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 num1int 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 num1num2;
        /* 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(num1num2);
        /* 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


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(num1num2):
    """ 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(num1num2)
""" 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

Most Recommend Questions:-







More Questions:-


Post a Comment

0 Comments