+ 1
how can I write a simple while loop that sums the first 20 odd integers
4 Antworten
0
while (((num%2)!=0) && (i <=20)){
oddnumsum += num;
i++;
}
0
Int sum=0;
for(int i=1,count=0;count<20;i=i+2,count++){ sum+=i; }
Cout<<sum;
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;
0
int sum = 0;
Int i = 1;
while(i < 20){
sum += i;
i += 2;
}
cout << sum;