2017년 5월 25일 목요일

0525 수업내용_배열 역순 복사

#include <iostream>
using namespace std;
void reverse(const int list[],int newList[],int size);
void printArray(const int list[],int size);\

int main(){
 const int SIZE = 6;
 int list[] = {1,2,3,4,5,6};
 int newList[SIZE] = {0};

 reverse(list,newList,SIZE);

 cout<<"Origianl Array : ";
 printArray(list,SIZE);
 cout<<"\n";

 cout<<"The reversed Array : ";
 printArray(newList,SIZE);
 cout<<"\n";

 return 0;
}

void reverse(const int list[],int newList[],int size)
{
 for(int i = 0,j=size-1;i<size;i++,j--)
 {
  newList[j] = list[i];
 }
}
void printArray(const int list[],int size){
 for(int i=0;i<size;i++)
  cout<<list[i]<<" ";
}

댓글 없음:

댓글 쓰기