C++Primerノート2

1762 ワード

/*
 * main.cpp
 *  Created on: 2012-2-16
 *      Author: XXX
 */

#include <iostream>
using namespace std;
void swap(int& first, int& secn);
void swap2(int& first, int& secn);
void swap3(int *first, int* secn);
void swap4(int &first, int &secn);
int main() {
//>>>>>>>>>>>>>>>>>>>>>>>6
	int firstn, secn;
	cout << "please input two num " << endl;
	cin >> firstn >> secn;
	swap4(firstn, secn);
	cout << firstn << endl;
	cout << secn << endl;
	for (int i = firstn, j = 0; i <= secn; i++, j++) {
		if (j % 10 == 0)
			cout << endl;
		cout << i << "	";
	}

	return 0;
}

/**
 *       
 */
void swap(int& first, int& secn) {
	if (first > secn) {
		first += secn;
		secn = first - secn;
		first = first - secn;
	}
}
/**
 *       
 *   :           2 ,      
 */
void swap2(int& first, int& secn) {
	if (first > secn) {
		first = first ^ secn;
		secn = first ^ secn;
		first = first ^ secn;
	}
}
/**
 *      
 */
void swap3(int *first, int* secn) {
	if (*first > *secn) {
		int tem = *first;
		*first = *secn;
		*secn = tem;
	}
}
/**
 *     
 */
void swap4(int &first, int &secn) {
	if (first > secn) {
		int tem = first;
		first = secn;
		secn = tem;
	}
}