#include<iostream>
using namespace std;
void sum(int n) {
int totalSum = 0;
while(n > 0) { // calculates until loop reaches n
totalSum = totalSum + n; // adds the no. to totalSum
n--; // decrements n to break the loop at the end
}
cout << totalSum << " " << endl;
}
int main(){
sum(5);
return 0;
}
OUTPUT-
15
No comments:
Post a Comment