Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Sum of numbers in a series using sum formular
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86 #include <iostream> double sum(int a, int b) { int big = b>a? b:a; int small = b>a? a:b; return ((a+b)/2.0)*(big - small +1); } int main() { int sum1{0}; for(int i = 3; i<=100; i++){ sum1 +=i; } std::cout << "Sum of numbers between 3 and 100 inclusive is: " << sum1 << std::endl; int x=3; int y = 100; std::cout<< "Sum between " << x << " and " << y << "[inclusive] = " << sum(x,y) << std::endl; std::cout << "Hello, world!\n"; }
run
|
edit
|
history
|
help
0
ADL of operator expression & unqualified function call
algorithm_1
parantheses matching using stack in C++ - test
copy
variable template not supported
ntohl
Struct packing
Why is vsnprintf Not Writing the Same Number of Characters as strncpy Would?
std::is_same doesn't check calling convension
base call virtual