Write a c++ program that calculates the addition of two numbers using pointers.
Program has three functions receiving two-pointers reference.
Three functions return int, float and double sum of numbers.
This c++ tutorial uses the following concepts.
- pointers in c++
- functions
- passing reference to a function
This code has been tested on code blocks c++ compiler
C++ source code
C++ source code
#include <iostream> using namespace std; int Sum(int *, int *); float Sum1(int *,int *); double Sum2(int *, int *); int main() { int a,b; cout<<"Enter 1st Value:"; cin>>a; cout<<"Enter 2nd Value:"; cin>>b; cout<<"...............ADDITION.............." <<endl <<endl; cout<<"The integer sum of these numbers is:"<<Sum(&a,&b)<<endl; cout<<"The float sum of these numbers is:"<<Sum1(&a,&b)<<endl; cout<<"The double sum of these numbers is:"<<Sum2(&a,&b)<<endl; cout<<endl <<endl; cout<<endl <<endl; return 0; } int Sum(int *x, int *y ) { int sum; sum=(*x + *y); return sum; } float Sum1(int *x,int *y ) { float sum; sum=(*x + *y); return sum; } double Sum2(int *x, int *y ) { double sum; sum=(*x + *y); return sum; }
Input-output of code
0 comments:
Post a Comment