From 991478f774594c0952e0919645d3bf871b64408d Mon Sep 17 00:00:00 2001 From: k0rrluna Date: Wed, 30 Apr 2025 02:14:23 +0300 Subject: [PATCH] exercise5 --- DeitelC/Chapter5/carRental.c | 29 +++++++++++++++++++++++++++++ DeitelC/Chapter5/exercise5-8.c | 14 ++++++++++++++ DeitelC/Chapter5/math | Bin 16040 -> 16104 bytes DeitelC/Chapter5/math.c | 17 +++++++++++++++++ DeitelC/Chapter5/roundingNumbers.c | 10 ++++++++++ 5 files changed, 70 insertions(+) create mode 100644 DeitelC/Chapter5/carRental.c create mode 100644 DeitelC/Chapter5/exercise5-8.c create mode 100644 DeitelC/Chapter5/roundingNumbers.c diff --git a/DeitelC/Chapter5/carRental.c b/DeitelC/Chapter5/carRental.c new file mode 100644 index 0000000..7b4c506 --- /dev/null +++ b/DeitelC/Chapter5/carRental.c @@ -0,0 +1,29 @@ +#include + +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)); + } + } +} diff --git a/DeitelC/Chapter5/exercise5-8.c b/DeitelC/Chapter5/exercise5-8.c new file mode 100644 index 0000000..257879a --- /dev/null +++ b/DeitelC/Chapter5/exercise5-8.c @@ -0,0 +1,14 @@ +#include +#include + +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); +} diff --git a/DeitelC/Chapter5/math b/DeitelC/Chapter5/math index 83e9c4ef869b707475a50c96f22af4601b4e3dd0..6ed021fb6e58d49f1cb2ddd8b42043ba779ff87a 100644 GIT binary patch delta 922 zcmZXSUr19?9LLW&*SR^T`x`40y9WLt(zPueb;GQjZ3_94JxG#+3W}wKW`VBFm*P4? z?ex$?4@NymFC{lfEb4+#tsXLv9wH3(uzl^(OKKG$X@(bfbx!&^b{2NedwOyiv^*O{9yssD7~83v{2Hp zuL7aVA?u);ep-yp?To$3(|Tvezyzcrc3b7y)KYIqUYBEe`9@Ce%_f6+DVU2_aAxBM z;KuG`Fee4GOa$hcnA;GN!E8V8%~MS&%kPUWq3)uYy2VJBpO5l( zyjPGqU}r{{v%fWM8n_H(hxiE`0H!uIZ5fERG;I^m4Ya{^-US}Q^qE+XZ_%%!2b(Ca zZHU{T&BWsRs0N;g`3Lj>frk^7wmalhMXBH;7NZF<9nY zPX8vix&H?A9`IcVRc^na2Lj5BbE}-HO(9b4Qq0Yx0$!#Q-qSciQ{E}iXrJ%oE(fwA zBlNPN16`ok{cb!+=Y4MP7@XD)KP2)9(*Ig$5_H!4*;&x}_TZ7yHJ>N)P;N*X_UL=OB7va}9GBKcnhoc45WImBLPfm;U_!pXR||cK}G_ z9XNTIVY9TzQ|`$PYzrnSh=ANMSzIB}kWrf18e}#r5U+Uu|9=CJz5%3H0O=P%Isiyt z{P6$(0U*8o)BpbuCVy0roqSJ$i*dr_mkRof3X>%j)fqJ=J1UBsaRSvn19``hPoRy- znU{_EAtMhv2ZIbys0N77fBgU78%V?DncRTVn=dN92RSQx@&R2BrW)bRTzX~9j1`j` z4c&p{NyC1i*yJc9r^#E4L?n}e#tSk@GDtXp%t3&H$q$Xh8S5tt8tW&v0M!UF@H6NO zL*&6$0-60laRCM?1_cL%J`ig*RK2GlL>%k|AaeoKE_C&4CT}znXFUeeHF+bGFyr;f z7mdZ4J~3{7Wt_!0Io?!z^JLSjjFS&Av24yTU%<>LHJQ^|pQ{Gy8lY#KtlfY<>$KJv z#E9j|C$05`HYh+G0;A6`Z054DV*-Y_r=2<11!IWp55~z|c4k~BOd(t;AlF 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; } diff --git a/DeitelC/Chapter5/roundingNumbers.c b/DeitelC/Chapter5/roundingNumbers.c new file mode 100644 index 0000000..61b52d9 --- /dev/null +++ b/DeitelC/Chapter5/roundingNumbers.c @@ -0,0 +1,10 @@ +#include +#include + +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); +}