Program to add two numbers using function

Problem Statement:- Program for the addition of two numbers using function.

Sample Input/Output:-


Sample Input First:

5

6

Sample Output First: 

11

Sample Input Second: 

100

77

Sample Output Second: 

177


Data requirement:-


  Input Data:- num1, num2

Additional Data:- sum


  Output Data:-add


Program in C

Here is the source code of the C Program for the addition of two numbers using function.


Code:

#include <stdio.h>/*printf,scanf definitions */
/* This function calculating additon of two numbers. */
int addition_two_numbers(int num1int num2)
{
    /* Calculating the sum of two numbers
    and store into sum variables */
    int sum = num1 + num2;
    return sum;
}
int main()
{
    int num1num2;
    /* Get the input of two variables */
    printf("Enter the Two Numbers:");
    scanf("%d%d", &num1, &num2);
    /* Call Function addition_two_numbers with two Parameters*/
    int add = addition_two_numbers(num1num2);
    /* Display sum of two numbers*/
    printf("Addition of two Numbers is: %d"add);
}


Input/Output:

Enter the Two Numbers:5 6

Addition of two Numbers is: 11


Program in C++

Here is the source code of the C++ Program to add two numbers using function.


Code:

#include <iostream>
using namespace std;
/* This function calculating additon of two numbers. */
int AdditionOfTwoNumbers(int num1int num2)
{
    /* Calculating the sum of two numbers
    and store into sum variables */
    int sum = num1 + num2;
    return sum;
}
int main()
{
    int num1num2;
    /* Get the input of two variables */
    cout << "Enter the Two Numbers:";
    cin >> num1 >> num2;
    /* Call Function addition_two_numbers with two Parameters*/
    int add = AdditionOfTwoNumbers(num1num2);
    /* Display sum of two numbers*/
    cout << "Addition of two Numbers is: " << add;
}


Input/Output:

Enter the Two Numbers:100 77

Addition of two Numbers is: 177


Program in Java

Here is the source code of the Java Program for the addition of two numbers using function.


Code:

import java.util.Scanner;

public class SumOfTwoNumbers {
    /* This function calculating additon of two numbers. */
    static int additionOfTwoNumbers(int num1int num2) {
        /*
         * Calculating the sum of two numbers and store 
into sum variables
         */
        int sum = num1 + num2;
        return sum;
    }

    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 addition_two_numbers with 
           two Parameters */
        int add = additionOfTwoNumbers(num1, num2);
        /* Display sum of two numbers */
        System.out.println("Addition of two Numbers is: " + add);
        sc.close();

    }
}


Input/Output:

Enter the Two Numbers:33 102

Addition of two Numbers is: 135


Program in Python

Here is the source code of the Python Program to add two numbers using function.


Code:

""" This function calculating additon of two numbers. """
def addition_two_numbers(num1num2):
    '''Calculating the sum 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 addition_two_numbers with two Parameters'''
add = addition_two_numbers(num1num2)
print("Addition of two Numbers is: "add)


Input/Output:

Enter the Two Numbers:

1000

2000

Addition of two Numbers is:  3000

Most Recommend Questions:-







More Questions:-


Post a Comment

0 Comments