-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5_11.c
32 lines (28 loc) · 901 Bytes
/
5_11.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
double roundTointeger(double );
double roundToTenths(double );
double roundToHundreths(double );
double roundToThousandths(double );
int main() {
double x;
printf("Enter a number:\n");
scanf_s("%lf", &x);
printf("Original Number:%f\tRandomed to greater integer:%f\n",x,roundTointeger(x));
printf("Original Number:%f\tRound to tenths:%f\n", x, roundToTenths(x));
printf("Original Number:%f\tRound to hundreths :%f\n", x, roundToHundreths(x));
printf("Original Number:%f\tRound to thousandths:%f\n", x, roundToThousandths(x));
}
double roundTointeger(double x) {
return floor(x + .5);
}
double roundToTenths(double x) {
return floor(x * 10 + .5) / 10;
}
double roundToHundreths(double x) {
return floor(x * 10 + .5) / 100;
}
double roundToThousandths(double x) {
return floor(x * 10 + .5) / 1000;
}