pex6_1.cpp

来自「数据结构C++代码,经典代码,受益多多,希望大家多多支持」· C++ 代码 · 共 49 行

CPP
49
字号
#include <iostream.h>
#pragma hdrstop

#include "wex6_5.h"

void main(void)
{
	int a = 3, b = 5;
	float x = 2.987, y = -6.532;
	char s[20], t[20];

	// output original values of a/b and x/y
	cout << "Original a/b and x/y: ";
	cout << a << '/' << b << "  " << x << '/' << y << endl;
	
	// swap a/b and x/y
	Swap(a,b);
	Swap(x,y);
	
	// print the swapped values
	cout << "Swapped a/b and x/y: ";
	cout << a << '/' << b << "  " << x << '/' << y
		 << endl << endl;
	
	// enter two strings s and t. strings may contain blanks
	// and terminate when newline is typed
	cout << "Enter string s: ";
	cin.getline(s,20,'\n');
	cout << "Enter string t: ";
	cin.getline(t,20,'\n');

	// swap strings s and t
	Swap(s,t);
	// print the swapped strings
	cout << "The swapped values of s and t are: ";
	cout << '\'' << s << "'  " << '\'' << t << '\'' << endl;
}

/*
<Run>

Original a/b and x/y: 3/5  2.987/-6.532
Swapped a/b and x/y: 5/3  -6.532/2.987

Enter string s: hello
Enter string t: to the world
The swapped values of s and t are: 'to the world'  'hello'
*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?