Problem
Take two integer inputs from user. Create Sum function which should receive two integers using pointers. Calculate the sum and display the result in main function.Code
#include "stdafx.h"#include <iostream>
#include<conio.h>
using namespace std;
int sum (int *, int *);
int main()
{
int a,b,c;
cout << "Enter 1st number: ";
cin >> a;
cout<<"enter 2nd number: ";
cin >> b;
c = sum (&a,&b);
cout << "Sum = "<< c << endl;
cout<<"Press any key to close.";
getch();
return 0;
}
int sum (int *a, int *b)
{
int c;
c = (*a + *b);
return c;
}
Output
Add/Sum two numbers using pointers in C/C++ Language |
This comment has been removed by a blog administrator.
ReplyDelete