This commit is contained in:
2025-05-06 03:36:02 +03:00
parent 991478f774
commit 785c2b0e50
14 changed files with 225 additions and 2 deletions

View File

@ -1,10 +1,38 @@
#include <stdio.h>
#include <math.h>
int roundToInteger(double number);
int roundToTenths(double number);
int roundToHundreths(double number);
int roundToThousandths(double number);
int main (void) {
double num;
printf("%s\n", "Enter a number!");
scanf("%lf", &num);
int y = floor(num + .5);
printf("%3s\t%3lf\t%3s\t%3d\n", "Orginal num:", num, "Rounded: ", y);
printf("%3s\t%3lf\t%3s\t%3d\n", "Orginal num:", num, "Rounded: ", roundToInteger(num));
printf("%3s\t%3lf\t%3s\t%3d\n", "Orginal num:", num, "Rounded: ", roundToTenths(num));
printf("%3s\t%3lf\t%3s\t%3d\n", "Orginal num:", num, "Rounded: ", roundToHundreths(num));
printf("%3s\t%3lf\t%3s\t%3d\n", "Orginal num:", num, "Rounded: ", roundToThousandths(num));
}
int roundToInteger(double number) {
int y = floor(number + .5);
return y;
}
int roundToTenths(double number) {
int y = floor(number * 10 + .5) / 10;
return y;
}
int roundToHundreths(double number) {
int y = floor(number * 100 + .5) / 100;
return y;
}
int roundToThousandths(double number) {
int y = floor(number * 1000 + .5) / 1000;
return y;
}