From 3ac18efdf9dc3a29ffe57650d8ce0167a63769e2 Mon Sep 17 00:00:00 2001 From: Hizenberg Date: Fri, 10 May 2024 11:18:45 +0530 Subject: [PATCH] Ceil function update --- cpadv.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cpadv.cpp b/cpadv.cpp index 447d528..c0cc0b5 100644 --- a/cpadv.cpp +++ b/cpadv.cpp @@ -105,6 +105,32 @@ ld sq_root(T x){ } +//When no problem of int overflow... +int ceil2(int a, int b) { + return (a + b - 1) / b; +} + +//When facing the Problem of int overflow.... +int ceil2(int a, int b) { + if (a == 0) return 0; + return (a - 1)/b + 1; +} + +//Approach 3 +int ceil2(int a, int b) { + int c=a/b; + if(a % b ! =0) c++; + return c; +} + +//Approach 4 +int ceil2(int a, int b){ + int c = a / b; + if (c * b < a) c++; + return c; +} + + template void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; } template