Re: Summation of odd numbers

Posted 19 October 2012 - 02:11 AM

Well, you're only asking the user to enter a number once. I am not sure what the actual requirements are, so I am going to assume that the user enter N inputs and from those inputs the sum of odd numbers is determined.

This can be easily implemented as:

// Get the amount of times the user wants to enter a number
input = Retrieve input from console
N = Parse(input)
// Some variable declaration
long input;
long sumOddNr = 0;
// Loop N times to request userinput
for i = 1 to N
// Retrieve the value the user inputs
input = Retrieve input from console
currentNumber = Parse(input);
// Determine if the user number is odd. if yes, sum it to the sumOddNr
if(currentNumber %2 != 0)
sumOddNr = sumOddNr + currentNumber;
endif
endfor

Note that this is not actual code. It's pseudocode to display the outline of the algorithm.