1. Identify and correct the errors in each of the following statements:
a)
for (a = 25, a <= 1, a--); {printf("%d\n", a);}
b) The following code should print whether a given integer is odd or even:
switch (value) {case (value % 2 == 0):puts("Even integer");case (value % 2 != 0):puts("Odd integer");}
c) The following code should calculate incremented salary after 10 years:
for (int year = 1; year <= 10; ++year) {double salary += salary * 0.05;}printf("%4u%21.2f\n", year, salary);
d)
for (double y = 7.11; y != 7.20; y += .01)printf("%7.2f\n", y);e) The following code should output all multiples of 3 from 1 to 100:for (int x = 3; x <= 100; x%3 == 0; x++ ) {printf("%d\n", x);}
e) The following code should output all multiples of 3 from 1 to 100:
for (int x = 3; x <= 100; x%3 == 0; x++ ) {printf("%d\n", x);}
Answer a:
the loop will never execute as the condition is false
corrected Code:
for (a = 25, a >= 1, a--); {printf("%d\n", a);}
Answer b:
switch (value%2) {
case 0:
puts("Even integer");
break;
case 1:
puts("Odd integer");}
break;
}
Answer c:
double salary=1000;
for (int year = 1; year <= 10; ++year) {
salary+= salary * 0.05;
}
printf("%4u%21.2f\n", year, salary);
Answer d:
for (int x = 3; x <= 100; x+=3 ) {
printf("%d\n", x);
}
Answer e:
for (int x = 3; x <= 100; x+=3 ) {
printf("%d\n", x);
}
Get Answers For Free
Most questions answered within 1 hours.