add range check

This commit is contained in:
2026-03-05 11:09:00 +03:00
parent d31d7827a6
commit d83a311237

View File

@@ -44,7 +44,7 @@ double do_while_fn(Context* ctx)
r += iter_fn(ctx->x, i);
++i;
}
while (i <= ctx->i);
while (i <= ctx->n);
return r;
}
@@ -57,8 +57,20 @@ void lab_3()
printf("Enter [x]: ");
READ_EXACT("%lf", ctx.x);
printf("Enter [N]: ");
READ_EXACT("%u", ctx.n);
do
{
printf("Enter [N]: ");
READ_EXACT("%u", ctx.n);
if (ctx.n < ctx.i)
{
printf("N could not be less than I=1, try again\n");
continue;
}
break;
}
while(1);
LoopFn* loop_fn;