Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Calculate sum between two numbers using for-, while-, and do-while loops
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86 #include <iostream> using namespace std; int main() { int sum{0}, sum2{0}; int start = 10; while(start <= 201){ cout << start << " "; sum += 5*start +1; start++; } cout << endl << "\n\nSum with while loop " << sum<< endl; cout << "\n\nNow with for loop: \n"; for(int start = 10, end = 201; start<= end; start++){ cout << start << " "; sum2+=start*5 +1; } cout<<endl << "\n\nSum from for-loop : " <<sum2 << endl; int beg{10}, end{201}, doSum{0}; do{ cout << beg << " "; doSum += beg*5 +1; ++beg; }while(beg <=end); cout << "\n\nSum with do while: " << doSum << endl; return 0; }
run
|
edit
|
history
|
help
0
CommandQueue
hangman
Multi Inheritance
#30.3
Adaptive return type
template test
Problem_onoff_3
MSVC_example_GetAllocLength
Two-phase sample with VC++ 2015
Catching divide-by-zero with /EHc