Skip to content

Commit

Permalink
Update ex6_10.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooophy authored and pezy committed Jun 23, 2015
1 parent 4dfe99f commit 3c19bc8
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions ch06/ex6_10.cpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,29 @@
//!@Alan
//!@Yue wang
//!
//! Exercise 6.10:
//! Using pointers, write a function to swap the values of two ints.
//! Test the function by calling it and printing the swapped values.
//!



#include <iostream>
#include <string>
#include <stdexcept>

using namespace std;

void swap(int* _n1, int* _n2);
void swap(int* lhs, int* rhs)
{
int tmp;
tmp = *lhs;
*lhs = *rhs;
*rhs = tmp;
}

int main()
{
int n1, n2;

cout<<"Please Enter:\n";
while(cin>>n1>>n2)
for (int lft, rht; std::cout << "Please Enter:\n", std::cin >> lft >> rht; )
{
swap(&n1, &n2);
cout<<n1<<" "<<n2<<endl;
swap(&lft, &rht);
std::cout << lft << " " << rht << std::endl;
}

return 0;
}

void swap(int* _n1, int* _n2)
{
int temp;
temp = *_n1;
*_n1 = *_n2;
*_n2 = temp;
}

0 comments on commit 3c19bc8

Please sign in to comment.