add 5 and 6
This commit is contained in:
parent
39f7a17cc1
commit
1d200f9534
23
pset2/5-shopping.c
Normal file
23
pset2/5-shopping.c
Normal 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
18
pset2/6-triangle.c
Normal 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;
|
||||
}
|
Loading…
Reference in a new issue