add 5 and 6

This commit is contained in:
juan 2021-09-29 22:20:05 +08:00
parent 39f7a17cc1
commit 1d200f9534
No known key found for this signature in database
GPG key ID: 5C1E5093C74F1DC7
2 changed files with 41 additions and 0 deletions

23
pset2/5-shopping.c Normal file
View file

@ -0,0 +1,23 @@
#include <stdio.h>
int main(void) {
// add up money
int total = 0, single;
for (int i = 0; i < 4; i++) {
scanf("%i", &single);
total += single;
}
// evaluate results
if (total >= 40) {
printf("%i", total);
} else if (total >= 30) {
printf("%i", total + 5);
} else if (total >= 20) {
printf("%i", total + 8);
} else {
printf("%i", total + 10);
}
return 0;
}

18
pset2/6-triangle.c Normal file
View file

@ -0,0 +1,18 @@
#include <math.h>
#include <stdio.h>
int main(void) {
// Initialize values
int a, b, c;
scanf("%i %i %i", &a, &b, &c);
// Calculate S and area's 2 power
double s = (a + b + c) / (double)2;
double area = (s * (s - a) * (s - b) * (s - c));
// Print answer
(area > 0) ? printf("%.3lf", sqrt(area))
: printf("The edges cannot make up of a triangle.");
return 0;
}