반응형


C++ 기초플러스 4판 7장 : 함수 _ 프로그래밍연습

#include <iostream>
using namespace std;

int Fill_array(double * Arr, int len);
void Show_array(const double * Arr, const int len);
void Reverse_array(double * Arr, int len);

int main(){
 int num;

 cout << "size? : ";
 bool F = cin >> num;
 if(!F) {
  cout << "are you died me?\n";
  return 0;
 } 

 double * Arr = new double[num]; 
 
 num = Fill_array(Arr, num);
 Show_array(Arr, num);
 Reverse_array(Arr, num);
 Show_array(Arr, num);
 Reverse_array(Arr+1, num-2);
 //else Arr = Reverse_array(Arr, num);
 Show_array(Arr, num);
 
 delete [] Arr;
 return 0;
}

int Fill_array(double * Arr, int len){
 for(int i = 0; i < len ; i++){
  cout << i+1 << "'s double type input : ";
  if(! (cin >> Arr[i]) ) break;
 }
 return i;
}
void Show_array(const double * Arr, const int len){
 for(int i = 0; i < len ; i++){
  cout << Arr[i] << "  ";
 }
 cout << "\n";
}
void Reverse_array(double * Arr, int len){
 double temp;
 for(int i = 0, int j = len-1; i < j ; i++, j--){
  temp = Arr[i];
  Arr[i] = Arr[j];
  Arr[j] = temp;
 }
}

 

 

반응형
Posted by Rainfly
l