mirror of
https://github.com/Hizenberg469/Algorithms-snippets.git
synced 2026-04-19 22:52:23 +03:00
Ceil function update
This commit is contained in:
26
cpadv.cpp
26
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 <typename Arg1>
|
||||
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
|
||||
template <typename Arg1, typename... Args>
|
||||
|
||||
Reference in New Issue
Block a user