diff --git a/Binaries/Swap b/Binaries/Swap new file mode 100755 index 0000000..9ce74ff Binary files /dev/null and b/Binaries/Swap differ diff --git a/Decimal Cleaner.c b/Decimal Cleaner.c new file mode 100644 index 0000000..d1201c2 --- /dev/null +++ b/Decimal Cleaner.c @@ -0,0 +1,25 @@ + std::string Round(const double value, const int decimals) + { + return CleanDecimals(std::round(value * std::pow(10, decimals)) / std::pow(10, decimals)); + } + + std::string CleanDecimals(const double value) + { + std::string result = std::to_string(value); + const int size = (int)result.size(); + for (int i = size - 1; i > 0; i--) + { + if (result[i] != '0' && i < size - 1) + { + result.erase(i + 1, size); + break; + } + } + + /* Check if the last char is a dot */ + if (result[result.size() - 1] == '.') + result.erase(result.size() - 1, 1); + + return result; + } + diff --git a/Swap.c b/Swap.c new file mode 100644 index 0000000..48c313f --- /dev/null +++ b/Swap.c @@ -0,0 +1,23 @@ +/* See https://git.disroot.org/oink/C for more details. + * + * Swap is a program that assigns a value to two variables, + * and swaps their values. Swap prints the values of each + * variable before and after their values are swapped. + */ +#include +#include + +int main() { + float a = 1.1, b = 2.2, temp; /* Example variables for swap */ + + printf("a = %.2f; b = %.2f\n", a, b); /* BEFORE */ + + /* Swap a and b */ + temp = a; + a = b; + b = temp; + + printf("a = %.2f; b = %.2f\n", a, b); /* AFTER */ + + return 0; +} diff --git a/Weather.c b/Weather.c index 712a5bf..528cb86 100644 --- a/Weather.c +++ b/Weather.c @@ -2,7 +2,7 @@ #include int main() { - int u, d, c; /* Temperature Unit and # of Dergreesn */ + int u, d, c; /* Temperature Unit and # of Dergrees */ printf("Wheather\n");