Question

Convert the following nested do-while loop into a nested for loop:
i = 0;
do
{
i = i+1;
j = i;
do
{
if( (i+j)%2 == 0 )
printf("%d", i);
else
printf("%d", j);
j = j+2;
}while(j < = 10);
}while(i <= 5);
Verify that you get the same output in each case.

19 Mar 2023
Answer :
Word Count : 326

The nested do-while loop that needs to be converted to a nested for loop:

i = 0;

do

{

i = i+1;

j = i;

do

{

if( (i+j)%2 == 0 )

printf("%d ", i);

else

printf("%d ", j);

j = j+2;

}while(j <= 10);

}while(i <= 5);

 

The equivalent nested for loop:

 

for (int i = 1; i <= 5; i++) { for (int j = i; j <= 10; j += 2) {

________ _________ ________ ____ _____ ___ _________ _______ ___ ________.
___ _______ ____ _______ ___ ____.
__________ _____ ________ _______ ___ __________ __________.
_________ ________ _____ ____ ____ _______ _________ ______.
____ _____ ___ _______ ___ ______ ________ _______ _____ ________ _________.
____ _______ ___ _________ ________.
___ __________ ____ __________ ____ __________ ___ __________ _____ __________.
_____ ___ _______ ________ ________ ________ _____ ___ _________ __________ ________ ________.
___ ___ ______ ______ ________ ________ ___ ____.
_________ ______ ___ ___ __________ ___.
_____ _______ _________ __________ _____ _________ ___ ___.
______ ____ _______ __________ ____ ____ ____ __________ ________.
_____ ______ _________ ________ _________ ________ _______.
___ ____ ________ _________ ______.
_________ _________ ________ ____ ___ _________ __________ _________ _______ ________ ____.
____ _____ ________ _________ ____ __________ _______.
______ _________ ________ ______ ______ ___ ______ _________ _________.
__________ ___ ______ _____ __________ _______ _______ ____ _______ _________.
___ ____ _______ ____ ________.
___ ________ ___ _______ __________ ________ ________ ____ __________.
_______ _________ __________ __________ _________.
_____ _______ _______ ______ ________ __________ ____.
____ ______ ______ ___ ____.
___ _____ ________ _____ ________ _____ _____ ________ _____ _____ __________.
___ ___ _____ _________ __________.
______ ___ ____ ________ _________.
______ ______ __________ ____ ______ _______ ______ ___.
__________ _____ ___ ______ ______.
_____ ______ __________ ______ _________ ________ _________ ____ __________.
______ ____ _____ _____ ___.
_____ __________ ___ ______ _____ _________ _______ __________ __________ ________ __________.
_________ __________.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU MMT 1 2023 - Convert the following nested do-while loop into a nested for loop:i | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→