YouTip LogoYouTip

Cpp Examples Sum Natural Number

# C++ Example - Sum of Natural Numbers [![Image 3: C++ Examples](#) C++ Examples](#) Calculate the sum of 1+2+3+....+n. ## Example #includeusing namespace std; int main(){int n, sum = 0; cout<>n; for(int i = 1; i<= n; ++i){sum += i; }cout<<"Sum = "<<sum; return 0; } The output of the above program is: Enter a positive integer: 50Sum = 1275 [![Image 4: C++ Examples](#) C++ Examples](#)
← C Function PutsServer Time β†’