added programs
This commit is contained in:
10
programs/p310/info.json
Normal file
10
programs/p310/info.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"language": "C",
|
||||
"name": "演習 3-10",
|
||||
"description": "3つの整数値の等価検証プログラム。",
|
||||
"output": {
|
||||
"type": "screenshot",
|
||||
"content": "./assets/p310.png"
|
||||
},
|
||||
"note": ""
|
||||
}
|
||||
BIN
programs/p310/main
Executable file
BIN
programs/p310/main
Executable file
Binary file not shown.
69
programs/p310/main.c
Normal file
69
programs/p310/main.c
Normal file
@@ -0,0 +1,69 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define NON_EQUAL 0
|
||||
#define ONE_EQUAL 1
|
||||
#define ALL_EQUAL 2
|
||||
|
||||
#ifndef USE_ALT
|
||||
|
||||
int main(void) {
|
||||
int a, b, c;
|
||||
|
||||
printf("Int A: ");
|
||||
scanf("%d", &a);
|
||||
printf("Int B: ");
|
||||
scanf("%d", &b);
|
||||
printf("Int C: ");
|
||||
scanf("%d", &c);
|
||||
|
||||
if (a == b && a == c) {
|
||||
printf("All three values are equal.\n");
|
||||
} else if (a != b && a == c) {
|
||||
printf("Two values are equal.\n");
|
||||
} else if (a != c && a == b) {
|
||||
printf("Two values are equal.\n");
|
||||
} else if (b == c) {
|
||||
printf("Two values are equal.\n");
|
||||
} else {
|
||||
printf("All three values are different.\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // !(defined(USE_ALT))
|
||||
|
||||
#ifdef USE_ALT
|
||||
|
||||
// alternetive answer
|
||||
int main(void) {
|
||||
int flag = 0; // remember, boolean in C is just integer
|
||||
|
||||
int a, b, c;
|
||||
|
||||
printf("Int A: ");
|
||||
scanf("%d", &a);
|
||||
printf("Int B: ");
|
||||
scanf("%d", &b);
|
||||
printf("Int C: ");
|
||||
scanf("%d", &c);
|
||||
|
||||
flag += a == b;
|
||||
flag += a == c;
|
||||
|
||||
if (flag != ALL_EQUAL) {
|
||||
flag += b == c;
|
||||
}
|
||||
|
||||
if (flag == NON_EQUAL) {
|
||||
printf("All three values are different.\n");
|
||||
} else if (flag == ONE_EQUAL) {
|
||||
printf("Two values are equal.\n");
|
||||
} else {
|
||||
printf("All three values are equal.\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // defined(USE_ALT)
|
||||
10
programs/p311/info.json
Normal file
10
programs/p311/info.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"language": "C",
|
||||
"name": "演習 3-11",
|
||||
"description": "論理OR演算子を使用して2つの整数値の差が10以下であるか、11以上であるかを検証するプログラム。",
|
||||
"output": {
|
||||
"type": "screenshot",
|
||||
"content": "./assets/p311.png"
|
||||
},
|
||||
"note": ""
|
||||
}
|
||||
BIN
programs/p311/main
Executable file
BIN
programs/p311/main
Executable file
Binary file not shown.
20
programs/p311/main.c
Normal file
20
programs/p311/main.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int a, b;
|
||||
|
||||
printf("Int A: ");
|
||||
scanf("%d", &a);
|
||||
printf("Int B: ");
|
||||
scanf("%d", &b);
|
||||
|
||||
int diff = a - b;
|
||||
|
||||
if (diff >= 11 || diff <= -11) {
|
||||
printf("Difference is greater than or equal to 11.\n");
|
||||
} else {
|
||||
printf("Difference is less than or equal to 10.\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user