The values in an array are stored in reverse order. For example: Originally is 6,5,4,3,2,1, request changes to 1,2,3,4,5,6

Source: Internet
Author: User
         
* * Copyright (c) 2012, Computer College of Yantai University         
* All rights reserved.         
* Author:  Liu Tongbin       
* Date of Completion: November 24, 2012         
* Version number: v1.0                 
* Input Description:    
* Problem Description: Re-store the values in an array in reverse order. For example: The original is 6,5,4,3,2,1, request to 1,2,3,4,5,6
* problem-solving ideas: In the middle element as the center, the two sides of the symmetrical elements of the value interchange
* Program output:
* Problem Analysis: slightly        
* algorithm design: slightly         
* *

#include <iostream>

using namespace std;

int main ()
{
	int a[10],i;

	int temp;

	cout<< "Please enter the original sequence (10 integers):" <<endl;

	for (i=0;i<=9;i++)
	{
		cin>>a[i];
	}

	for (i=0;i<5;i++)  //The key is this loop, which swaps the values of symmetric elements.
	{
		temp=a[i];

		A[I]=A[10-I-1];

		a[10-i-1]=temp;

	}

	cout<< "Sequence of Reverse discharge:" <<endl;

	for (i=0;i<=9;i++)
	{
		cout<<a[i]<< "";
	}

	cout<<endl;

	return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.