+ 1

how can I write a simple while loop that sums the first 20 odd integers

14th Jun 2016, 5:37 PM
Abdulai Torfik
4 Réponses
0
while (((num%2)!=0) && (i <=20)){ oddnumsum += num; i++; }
14th Jun 2016, 6:24 PM
Guillermo Fernández
Guillermo Fernández - avatar
0
Int sum=0; for(int i=1,count=0;count<20;i=i+2,count++){ sum+=i; } Cout<<sum;
14th Jun 2016, 6:42 PM
CHIRANJEEV
CHIRANJEEV - avatar
0
Or, if you want a while loop Int sum =1; Int count =1; Int i=1; While (count++,i= i+2, count <=20){ sum+=i; } Cout <<sum;
14th Jun 2016, 6:52 PM
CHIRANJEEV
CHIRANJEEV - avatar
0
int sum = 0; Int i = 1; while(i < 20){ sum += i; i += 2; } cout << sum;
7th Jul 2016, 9:49 PM
Tony Christopher
Tony Christopher - avatar