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

📄 pr0631.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
//  Problem 6.31 on page 146
//  Computing statistics

#include <iostream>  // defines the cout object
using namespace std;

const int SIZE = 100;
void read(double[],int&);
double mean(double[],int);

int main()
{ double x[SIZE];
  int n=0;
  read(x,n);
  double m = mean(x,n);
  cout << "mean = " << m << endl;
  for (int i=0; i<n; i++)
    cout << "x[" << i << "] = " << x[i]
         << ", dev[i] = " << x[i] - m << endl;
}

void read(double x[], int& n)
{ cout << "Enter data.  Terminate with 0:\n";
  while (n<SIZE)
  { cout << "x[" << n << "]: ";
    cin >> x[n];
    if (x[n] == 0) break;
    else ++n;
  }
}

double mean(double x[], int n)
{ double sum=0;
  for (int i=0; i<n; i++)
    sum += x[i];
  return sum/n;
}

⌨️ 快捷键说明

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