Monday, November 13, 2017

Add/Sum two numbers using pointers in C/C++ Language

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
Add/Sum two numbers using pointers in C/C++ Language

1 comment :

Note: Only a member of this blog may post a comment.

Copyright 2017. All Rights Reserved. Privacy Policy / Terms And Conditions / Sitemap / Contact