The loop shown below has been written by a c++ programmer
int n =1; //A
while (n>=1){
if(condition){ //B
//C
}
n--;
}
1)Update the value of the variable n to repeat the loop 10 times.
2)Write the condition Statement to select only odd numbers
3)Rewrite the code with the statement n++ (You can only add or modify statement A,B,C)
1) int n = 10
2) if(n%2 == 1)
3) int n = 1; //A
while (n>=1){
if(n > 1){ //B
break;//C
}
n++;
}
Comments
Leave a comment