Find the error in each of the following For x 100 x 1 x pr

Find the error in each of the following. For (x = 100, x > 1, x++) printf (\"%i/n\", x); for (x = 0.000001; x = = 0.0001; x += 0.000001) {printf (\"%.7f\ \", x);} The following code should output the odd integers from 999 to 1: for (x = 999; x >1; x += 2) {printf (\"%i/n x);} The following code should output the even integers from 2 to 100: Counter = 2; Do {printf (\"%i/n\", counter); Counter += 2;} While (counter

Solution

a)
First error: in for loop the \'for\' should be of small case instead of \'For\'.
Second error: loop will go into infinite loop because of the condition. termination condition is x is greater than 1 which it holds always and never dissatisfy. So, loop will go into infinite execution.

b)
loop will not execute.
condition needs be modified to run that loop.

c)

Increamenting the x value incorrectly.

instead of x+=2, it should be x-=2

d)
First error:
the first letter of \'Do\' and \'While\' should be of small case.
like \'do\' and \'while\'

Second error:
it will not print 100 number.
Need to modify the while condition like while(c<=100);


e)
Error: semicolon after for loop.
remove the semi colon after the for loop then the total contains sun of integers from 100 to 150.

It will be like that:
for(x=100;x<=150;x++){
total+=x;
}

 Find the error in each of the following. For (x = 100, x > 1, x++) printf (\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site