MS(二)

在不用第三方参数的情况下,交换两个参数的值

//在不用第三方参数的情况下,交换两个参数的值

#include <stdio.h>
#include <iostream>
using namespace std;


int main(void)
{
	int a = 50;
	int b = 60;

	cout << "a: " << a << " b: " << b << endl;

	a = a + b; //a=110
	b = a - b; //b = 110 - 60 = 50
	a = a - b; //a = 110 - 50 = 60

	cout <<"swap..... "<<endl;
	cout << "a: " << a << " b:" << b << endl;
	system("pause");

	return 0;
}

//a: 50 b: 60
//swap.....
//a: 60 b:50
//请按任意键继续. . .



输入一个字符串,将其逆序后输出。(使用C++)


//输入一个字符串,将其逆序后输出。(使用C++,不建议用伪码)

#include <stdio.h>
#include <iostream>
using namespace std;

char *reverse_str(char *src)
{
	char str[1024];
	cout << sizeof(str) << endl;
	memset(str, 0, sizeof(str));

	strcpy(str,src);

	int i = 0, j = 0;
	char c_temp = '0';
	//abcde
	//01234
	for (i = 0, j = strlen(str) - 1; i < strlen(str)/2; i++, j--)
	{
		c_temp = str[i];
		str[i] = str[j];
		str[j] = c_temp;
	}

	return str;

}


int main(void)
{
	char string[1024];
	cin.getline(string,1024,'d'); //输入的字符串遇到字符d,结束。
	//cin.getline(string,1024); 
	cout << string << endl;

	cout << reverse_str(string) << endl;
	system("pause");

	return 0;
}

/*
aabbccddee
aabbcc
1024
ccbbaa
请按任意键继续. . .
*/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值