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; system("pause"); } int sum(int a, int b){ return a + b; }
page revision: 0, last edited: 09 Sep 2009 06:04