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

📄 sumct1.cpp

📁 data structures, algorithms and Application书的源代码
💻 CPP
字号:
// step count for sum of n numbers

#include <iostream.h>

int count = 0;

template<class T>
T Sum(T a[], int n)
{// Return sum of numbers a[0:n - 1].
   T tsum = 0;
   count++; // for tsum = 0
   for (int i = 0; i < n; i++) {
     count++; // for the for statement
     tsum += a[i];
     count++; // for assignment
     }
   count++; // for last execution of for statement
   count++; // for return
   return tsum;
}

void main(void)
{
   float a[6] = {1, 2, 3, 4, 5, 6};
   cout << Sum(a,6) << endl;
   cout << count << endl;
}

⌨️ 快捷键说明

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