From d83a311237e9542fd1613543f96a2967ebd6e93d Mon Sep 17 00:00:00 2001 From: matyushev_mo Date: Thu, 5 Mar 2026 11:09:00 +0300 Subject: [PATCH] add range check --- src/LAB3.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/LAB3.c b/src/LAB3.c index df52d7d..b23b48a 100644 --- a/src/LAB3.c +++ b/src/LAB3.c @@ -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;