Sunday, April 29, 2018

Swap Two Numbers Using Pointers in C++

A very simple program to ask the user to give two numbers and swap the arrangement of the numbers using functions and pointers in C++ programming language.

I am currently accepting programming work, it project, school programming projects , thesis and capstone projects, IT consulting work and web development work kindly contact me in the following email address for further details.  If you want to advertise in my website kindly contact me also in my email address also. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.



Program Listing

swap.cpp

#include <iostream>
#include <stdlib.h>

using namespace std;

void GetVal(int& Get1,int& Get2);
void SwapVal(int& Swap1,int& Swap2);
void ShowVal(int& Show1,int& Show2);

int main()
{
    int FirstNum,SecondNum;
    GetVal(FirstNum,SecondNum);
    SwapVal(FirstNum,SecondNum);
    ShowVal(FirstNum,SecondNum);
    system("PAUSE");
    return 0;
}

void GetVal(int& Get1,int& Get2)
{
 cout <<"SWAP TWO NUMBERS USING POINTERS AND FUNCTIONS IN C++";
cout << "Enter 2 values: ";
     cin >> Get1 >> Get2;
}

void SwapVal(int& Swap1,int& Swap2)
{
     int temp;
     temp = Swap1;
     Swap1 = Swap2;
     Swap2 = temp;
}

void ShowVal(int& Show1,int& Show2)
{
     cout << Show1 << "  " << Show2 << "\n";
}


No comments:

Post a Comment