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
const reference life time extension
pitch errors verification for Nowhk
hangman
Constant table but dynamic initialization at runtime
CIS-2207 Week1 Assignment1 Company Devisions
progrm_1
Build char string (multibyte) with wchar
Matrix paths right-down only, going through XY
ADL of operator expression & unqualified function call
empty base bug