第四课。

This commit is contained in:
unlockable
2022-10-07 12:29:08 +08:00
parent aedf18a247
commit c3608c3f89
4 changed files with 47 additions and 0 deletions

11
04/Exercise01.c Normal file
View File

@@ -0,0 +1,11 @@
#include <stdio.h>
#include <math.h>
int main() {
double dx, dy, df_1, df_2;
scanf("%lf %lf", &dx, &dy);
df_1 = (1 / sqrt(2 * 3.14)) * exp(-(dx * dx) / 2);
df_2 = sin(dx*dx + dy*dy) * cos(dx + dy) / 3;
printf("f_1 = %lf, f_2 = %lf", df_1, df_2);
return 0;
}

6
04/Exercise02.c Normal file
View File

@@ -0,0 +1,6 @@
#include <stdio.h>
int main() {
int result, x;
printf("%d", (5 > 3 && 2 || 8 < 4 - !0));
return 0;
}

13
04/Exercise03.c Normal file
View File

@@ -0,0 +1,13 @@
#include <stdio.h>
int main() {
int people[3] = {0};
for (int i = 0; i < 3; i++) {
people[i] = 1;
if ((people[1] == 1 || people[1] == 0) && (people[2] == 1 || people[2] == 0) && (people[2] == 0 || people[2] == 1)) {
printf("%d %d %d\n", people[0], people[1], people[2]);
}
people[i] = 0;
}
return 0;
}

17
04/Optional.c Normal file
View File

@@ -0,0 +1,17 @@
#include <stdio.h>
int main() {
int chicken[3] = {0};
for (int chick = 1; chick <= 100; chick++) {
for (int rooster = 1; rooster <= 100 - chick; rooster++) {
int hen = 100 - chick - rooster;
if ((hen > chicken[2]) && (chick*5 + rooster*10 + hen*15 == 1000)) {
chicken[0] = chick;
chicken[1] = rooster;
chicken[2] = hen;
}
}
}
printf("Chick: %d, Rooster: %d, Hen: %d", chicken[0], chicken[1], chicken[2]);
return 0;
}