exercise5
This commit is contained in:
parent
de35a9dd15
commit
991478f774
29
DeitelC/Chapter5/carRental.c
Normal file
29
DeitelC/Chapter5/carRental.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
|
||||
double calculateCharges (int hours);
|
||||
|
||||
int main (void) {
|
||||
printf("%5s\t%5s\t%5s\n", "Car", "Hours", "Charge");
|
||||
printf("%5s\t%5d\t%5.2f\n", "1", 22, calculateCharges(22));
|
||||
printf("%5s\t%5d\t%5.2f\n", "2", 12, calculateCharges(12));
|
||||
printf("%5s\t%5d\t%5.2f\n", "3", 34, calculateCharges(34));
|
||||
printf("%5s\t%5d\t%5.2f\n", "4", 48, calculateCharges(48));
|
||||
printf("%5s\t%5d\t%5.2f\n", "5", 94, calculateCharges(94));
|
||||
}
|
||||
|
||||
double calculateCharges (int hours) {
|
||||
int dayMod = hours % 24;
|
||||
int days = hours / 24;
|
||||
|
||||
if (days >= 1) {
|
||||
return ((days * 50)+(hours * 0.5));
|
||||
} else {
|
||||
if (hours <= 8) {
|
||||
return ((hours * 0.5) + 25);
|
||||
} else if (hours <= 13) {
|
||||
return (((hours - 8) * 5) + (hours * 0.5) + 25);
|
||||
} else {
|
||||
return (50 + (hours * 0.5));
|
||||
}
|
||||
}
|
||||
}
|
14
DeitelC/Chapter5/exercise5-8.c
Normal file
14
DeitelC/Chapter5/exercise5-8.c
Normal file
@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main (void) {
|
||||
double x;
|
||||
x = fabs(10.85);
|
||||
x = floor(10.85);
|
||||
x = fabs(-0.678);
|
||||
x = ceil(9.234);
|
||||
x = fabs(0.0);
|
||||
x = ceil(-34.87);
|
||||
x = ceil(-fabs(-12 - floor(-9.5)));
|
||||
printf("%.5f\n", x);
|
||||
}
|
Binary file not shown.
@ -2,6 +2,8 @@
|
||||
#include <math.h>
|
||||
|
||||
double hypotenuse (double side1, double side2);
|
||||
int smallest (int x, int y, int z);
|
||||
int intToFloat (double number);
|
||||
|
||||
int main (void) {
|
||||
printf("%.2f\n", cbrt(27.0));
|
||||
@ -18,9 +20,24 @@ int main (void) {
|
||||
printf("%.5f\n", cos(0.0));
|
||||
printf("%.5f\n", tan(0.0));
|
||||
printf("%.5f\n", hypotenuse(3.0,4.0));
|
||||
printf("%d\n", smallest(3,3,4));
|
||||
printf("%d\n", intToFloat(3.4));
|
||||
}
|
||||
|
||||
double hypotenuse (double side1, double side2) {
|
||||
double final = (side1*side1) + (side2*side2);
|
||||
return sqrt(final);
|
||||
}
|
||||
|
||||
int smallest (int x, int y, int z) {
|
||||
if (x <= y && x <= z) {
|
||||
return x;
|
||||
} else if (y <= z && y <= x) {
|
||||
return y;
|
||||
} else {
|
||||
return z;
|
||||
}
|
||||
}
|
||||
int intToFloat (double number) {
|
||||
return number;
|
||||
}
|
||||
|
10
DeitelC/Chapter5/roundingNumbers.c
Normal file
10
DeitelC/Chapter5/roundingNumbers.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user