Question: // A while loop for sum of first n positive integers. #include using namespace std; int main() { int n, i = 1; cout <
// A while loop for sum of first n positive integers. #includeusing namespace std; int main() { int n, i = 1; cout << "Enter a positive integer: "; cin >> n; long sum = 0; while (i <= n) sum += i++; cout << "Sum of first " << n << " positive integers = " << sum << endl; } // What is the value of sum for given n ?
|
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
