mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-05-08 15:14:01 +08:00
clang-format and clang-tidy fixes for 0ec45e33
This commit is contained in:
@@ -22,11 +22,11 @@ template <typename T>
|
||||
bool is_prime(T num) {
|
||||
bool result = true;
|
||||
if (num <= 1) {
|
||||
return 0;
|
||||
return false;
|
||||
} else if (num == 2) {
|
||||
return 1;
|
||||
return true;
|
||||
} else if ((num & 1) == 0) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (num >= 3) {
|
||||
for (T i = 3; (i * i) <= (num); i = (i + 2)) {
|
||||
@@ -47,7 +47,7 @@ int main() {
|
||||
assert(is_prime(50) == false);
|
||||
assert(is_prime(115249) == true);
|
||||
|
||||
int num;
|
||||
int num = 0;
|
||||
std::cout << "Enter the number to check if it is prime or not" << std::endl;
|
||||
std::cin >> num;
|
||||
bool result = is_prime(num);
|
||||
|
||||
@@ -2,14 +2,17 @@
|
||||
* @author [aminos 🇮🇳](https://github.com/amino19)
|
||||
* @file
|
||||
*
|
||||
* @brief [Program to count digits
|
||||
* in an integer](https://www.geeksforgeeks.org/program-count-digits-integer-3-different-methods)
|
||||
* @brief [Program to count digits
|
||||
* in an
|
||||
* integer](https://www.geeksforgeeks.org/program-count-digits-integer-3-different-methods)
|
||||
* @details It is a very basic math of finding number of digits in a given
|
||||
* number i.e, we can use it by inputting values whether it can be a
|
||||
* positive/negative value, let's say: an integer. There is also a second method:
|
||||
* by using "K = floor(log10(N) + 1)", but it's only applicable for
|
||||
* positive/negative value, let's say: an integer. There is also a second
|
||||
* method: by using "K = floor(log10(N) + 1)", but it's only applicable for
|
||||
* numbers (not integers).
|
||||
* For more details, refer to the [Algorithms-Explanation](https://github.com/TheAlgorithms/Algorithms-Explanation/blob/master/en/Basic%20Math/Finding the number of digits in a number.md) repository.
|
||||
* For more details, refer to the
|
||||
* [Algorithms-Explanation](https://github.com/TheAlgorithms/Algorithms-Explanation/blob/master/en/Basic%20Math/Finding
|
||||
* the number of digits in a number.md) repository.
|
||||
*/
|
||||
|
||||
#include <cassert> /// for assert
|
||||
@@ -29,7 +32,7 @@ int main() {
|
||||
|
||||
// iterate until `n` becomes 0
|
||||
// remove last digit from `n` in each iteration
|
||||
// increase `count` by 1 in each iteration
|
||||
// increase `count` by 1 in each iteration
|
||||
while (n != 0) {
|
||||
// we can also use `n = n / 10`
|
||||
n /= 10;
|
||||
|
||||
@@ -35,12 +35,14 @@ namespace cycle_detection {
|
||||
*/
|
||||
template <typename T>
|
||||
int32_t duplicateNumber(const std::vector<T> &in_arr, const uint32_t &n) {
|
||||
if (n == 0 || n == 1) { // to find duplicate in an array its size should be atleast 2
|
||||
if (n == 0 ||
|
||||
n == 1) { // to find duplicate in an array its size should be atleast 2
|
||||
return -1;
|
||||
}
|
||||
uint32_t tortoise = in_arr[0]; // variable tortoise is used for the longer
|
||||
// jumps in the array
|
||||
uint32_t hare = in_arr[0]; // variable hare is used for shorter jumps in the array
|
||||
uint32_t hare =
|
||||
in_arr[0]; // variable hare is used for shorter jumps in the array
|
||||
do {
|
||||
tortoise = in_arr[tortoise];
|
||||
hare = in_arr[in_arr[hare]];
|
||||
|
||||
Reference in New Issue
Block a user