Code:
int k, a;
a = 3;
k = 1;
while(k < 10)
printf(“\n%f AM %f”, k, k*a-1);
k = k + 2;
-
Error 1: The
printfstatement has a format specifier%f(float), but the variableskandk*a-1are integers. This will cause incorrect output or undefined behavior.- Fix: Change
%fto%dfor integer values.
- Fix: Change
-
Error 2: The
k = k + 2;statement is not inside thewhileloop because of the missing curly braces{}. The loop will only execute theprintfonce and then skip to thek = k + 2outside the loop.- Fix: Add curly braces to correctly define the loop body.
Corrected code:
int k, a;
a = 3;
k = 1;
while(k < 10) {
printf(“\n%d AM %d”, k, k*a-1);
k = k + 2;
}