inef.cpp

来自「一本全面剖析C++数据结构算法的书籍」· C++ 代码 · 共 31 行

CPP
31
字号
// ineffficient prefix sums#include <iostream.h>template <class T>T Sum(T a[], int n){// Return sum of numbers a[0:n - 1].   T tsum = 0;   for (int i = 0; i < n; i++)      tsum += a[i];   return tsum;}template <class T>void Inef(T a[], T b[], int n){// Compute prefix sums.   for (int j = 0; j < n; j++)      b[j] = Sum(a, j + 1);}void main(void){   int a[6] = {1, 2, 3, 4, 5, 6};   int b[6];   int n = 6;   Inef(a,b,n);   for (int i = 0; i < n; i++)      cout << b[i] << ' ';   cout << endl;}

⌨️ 快捷键说明

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