Problem Statement:
Write a Program that defines a function to calculate the sum of two integers and prints the result. Call this function by passing two integer values.
Approach:
- Define a function that takes two numbers as input.
- Add the two numbers inside the function.
- Call the function with two integers & print the result.
Example:
Input: 5, 3
Process: a + b => 5 + 3 = 8
Output: 8
Visualisation:

Explanation:
- ●
Sum(a, b)
is a function that takes two arguments. - ● Adds them and stores the result in a variable named
add
. - ● Prints the result.
- ●
Sum(a,b)
calls the function with a=5 & b=3, so it prints 8.
function sum(a, b) {
let add = a + b;
console.log(add);
}
sum(5, 3);
def sum(a, b):
add = a + b
print(add)
sum(5, 3)
public class Main {
public static void sum(int a, int b) {
int add = a + b;
System.out.println(add);
}
public static void main(String[] args) {
sum(5, 3);
}
}
#include <iostream>
using namespace std;
void sum(int a, int b) {
int add = a + b;
cout << add << endl;
}
int main() {
sum(5, 3);
return 0;
}
#include <stdio.h>
void sum(int a, int b) {
int add = a + b;
printf("%d\n", add);
}
int main() {
sum(5, 3);
return 0;
}
using System;
class Program {
static void Sum(int a, int b) {
int add = a + b;
Console.WriteLine(add);
}
static void Main() {
Sum(5, 3);
}
}