while loop : example
Problem: Write a method to determine the sum to N natural numbers. N is passed as a parameter. Return the computed sum as the function value.
int SumN (int N)
{ int Sum = 0;
while (N > 0)
{ Sum = Sum + N;
N = N - 1;}
return Sum; }
Previous slide
Next slide
Back to first slide
View graphic version