如何正确在评论中写出公式?

问题描述 投票:0回答:1

我想在注释中写这个公式:

the formula

这就是我在注释中写公式的方式:

// based on formula S = n/2 * (a + (a*n))

但是,如果我将注释与公式进行比较,则会缺少Sna1an部分。

我的问题是:如何在我的注释中正确编写公式?

comments formula
1个回答
0
投票

您应该在函数或代码之前的代码中使用多行注释。例如:

/*
 *  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
*/
© www.soinside.com 2019 - 2024. All rights reserved.