Decimal Cleaner, Swap, and Weather
This commit is contained in:
parent
339638c9d8
commit
79ea6545b1
4 changed files with 49 additions and 1 deletions
BIN
Binaries/Swap
Executable file
BIN
Binaries/Swap
Executable file
Binary file not shown.
25
Decimal Cleaner.c
Normal file
25
Decimal Cleaner.c
Normal file
|
@ -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;
|
||||
}
|
||||
|
23
Swap.c
Normal file
23
Swap.c
Normal file
|
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
int u, d, c; /* Temperature Unit and # of Dergreesn */
|
||||
int u, d, c; /* Temperature Unit and # of Dergrees */
|
||||
|
||||
printf("Wheather\n");
|
||||
|
||||
|
|
Loading…
Reference in a new issue