Recap - Sigma Function
Part of the Fundamentals section of Coddy's C++ journey — lesson 55 of 74.
Challenge
EasyWrite a function named sigma with one argument that represents a number n.
The function will return the sum of all the numbers from 1 to n (including).
For example, for sigma(5), the function will return 15, because 15 = 1 + 2 + 3 + 4 + 5.
Try it yourself
#include <iostream>
int sigma(int n) {
// Write your code below
}
int main() {
int n;
std::cin >> n;
int res = sigma(n);
std::cout << res;
return 0;
}All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic ShortcutsComparison OperatorsString Comparison10Functions
Declare a FunctionParametersReturn TypesFunction OverloadingRecap - Sigma FunctionRecap - Validation FunctionVoid Functions3Variables Part 2
Type DeclarationNaming ConventionsRecap - Initialize VariablesType Casting Part 1Type Casting Part 26Decision Making
If StatementIf - ElseSwitch StatementConditional OperatorRecap - If ElseNested If - Else