Hello I had a basic question that I wanted to make sure I had right.
Rewrite the following code using a do-while statement with no decisions in the loop body:
My answer was the following:Code:sum = 0; for (odd = 1; odd < n; odd = odd + 2) sum = sum + odd; printf("Sum of the positive odd numbers less than %d is %d\n", n, sum);
My question is did I correctly format the statement from a for to a do-while and did I do it correctly with no decisions in the loop body?Code:sum = 0; odd = 1; while(odd < n){ sum = sum + odd printf("Sum of the positive odd numbers less than %d is %d\n", n, sum); odd = odd + 2; }



1Likes
LinkBack URL
About LinkBacks



