View Code of Problem 49

// ConsoleApplication5.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<string>
using namespace std;
int main()
{
	int a[10];
	int temp;
	int n,min=0,max=0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; i++) {
			if (a[min] > a[i]) { min = i; }
			if (a[max] < a[i]) { max = i; }
	}
	temp = a[min];
	a[min]=a[0];
	a[0] = temp;
	

	temp = a[max];
	a[max] =  a[n - 1];
	a[n - 1] = temp;
	

	for (int i = 0; i < n; i++) {
		if (i != n - 1) {
			printf("%d ", a[i]);
		}
		else {
			printf("%d", a[i]);
		}
			
	}
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件

Double click to view unformatted code.


Back to problem 49