+ 3

How can an array be used to add all odd numbers in a certain range of numbers eg from 1-100

19th Feb 2017, 6:16 AM
Bukuru Henry
Bukuru Henry - avatar
3 Respostas
+ 1
use a for loop from 1 to 100 and an If condition: if(variable%2!=0) sum+=variable.
19th Feb 2017, 6:23 AM
Sandip
+ 1
int sum=0; for(int i=1; i<=100; i+=2){ sum+=i; } System.out.print(sum);
19th Feb 2017, 6:25 AM
Vikas Gupta
Vikas Gupta - avatar