Sum of two numbers using a function

How to use functions in C++

Program to read two numbers from the keyboard and print the sum using a function

#include <iostream>
using namespace std;
int sum(int a, int b); //declare the function
int main() {
   int a = 0, b = 0;
   cout << "Enter a number ";
   cin >> a;
   cout << "Enter another number ";
   cin >> b;
   int c = sum(a, b); //call the sum function
   cout << "sum = " << c << endl;
int sum(int a, int b){
    return a + b;
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License