我想在注释中写这个公式:
这就是我在注释中写公式的方式:
// based on formula S = n/2 * (a + (a*n))
但是,如果我将注释与公式进行比较,则会缺少Sn
,a1
和an
部分。
我的问题是:如何在我的注释中正确编写公式?
您应该在函数或代码之前的代码中使用多行注释。例如:
/*
* Formula to calculate sum of n numbers
* S = n/2 * (a + l)
* where S is the sum of n elements
* n is the number of elements
* a is the first element in the series
* l is the nth element in the series
*/