Saturday, 27 December 2014

How to Addition of two Numbers using Function Template (C++)?

The below program is more important in lab as well as interview. This program will explain you how to add two numbers using function in C++. Try to write a program and find out the answer. I have given answer for this program here.

Addition of two Numbers using Function Template




template<class T>

T add(T m,T n)




void main()


int a,b;

float x,y;

cout<<"Enter the two integer values";


cout<<"Enter two float values";


cout<<"The Addition of integer numbers:"<<add(a,b);

cout<<"The Addition of float numbers:"<<add(x,y);




Enter  the two integer values

45   55

Enter  two float values

24.5   25.5

The Addition of integer numbers:100

The Addition of float numbers: 50

All the best!!!