⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex0610.cpp

📁 practice c++, it is from the book http://www.amazon.com/Schaums-Outline-Programming-John-Hubbard
💻 CPP
字号:
//  Programming with C++, Second Edition, by John R. Hubbard
//  Copyright McGraw-Hill, 2000
//  Example 6.10 on page 132
//  Passing an array to a function

#include <iostream>
using namespace std;

void read(int a[], int& n);
// reads n elements into a[]

void print(int a[], int n);
// prints the first n elements of a[]

int main()
{ // reads and prints an array:
  const int MAXSIZE=100;
  int a[MAXSIZE]={0}, size;
  read(a,size);
  cout << "The array has " << size << " elements: ";
  print(a,size);
}

void read(int a[], int& n)
{ // reads n elements into a[]:
  cout << "Enter integers.  Terminate with 0:\n";
  n = 0;
  do
  { cout << "a[" << n << "]: ";  
    cin >> a[n];
  } while (a[n++] != 0);
  --n;  // don't count the 0
}

void print(int a[], int n)
{ // prints the first n elements of a[]
  for (int i=0; i<n; i++)
    cout << a[i] << " ";
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -