Finished first group of assignments

This commit is contained in:
2025-05-01 12:08:23 +09:00
parent 6a2eaa43d8
commit 0805e15bb9
27 changed files with 227 additions and 92 deletions

8
programs/lst22/info.json Normal file
View File

@@ -0,0 +1,8 @@
{
"name": "List 2ー2 +$\\\\alpha$",
"description": "2桁以上の正の整数の十の位の数字を表示するプログラム。",
"output": {
"type": "screenshot",
"content": "./assets/lst22.png"
}
}

BIN
programs/lst22/main Executable file

Binary file not shown.

18
programs/lst22/main.c Normal file
View File

@@ -0,0 +1,18 @@
#include <stdio.h>
int main(void) {
int n;
printf("Integer n: ");
scanf("%d", &n);
// Don't trust user input
if (n < 10) {
printf("Integer n must be more than 2 digits.");
return 1;
}
printf("Tens digit of interger n is %d.", n / 10 % 10);
return 0;
}

8
programs/prog1/info.json Normal file
View File

@@ -0,0 +1,8 @@
{
"name": "演習 2ー1",
"description": "2つの整数値を読み込み、前者の値が後者の何\\%であるかを表示するプログラム。",
"output": {
"type": "screenshot",
"content": "./assets/prog1.png"
}
}

BIN
programs/prog1/main Executable file

Binary file not shown.

15
programs/prog1/main.c Normal file
View File

@@ -0,0 +1,15 @@
#include <stdio.h>
int main(void) {
int x;
int y;
printf("Integer x: ");
scanf("%d", &x);
printf("Integer y: ");
scanf("%d", &y);
printf("Value of x is %d%% of y.", x * 100 / y);
return 0;
}

8
programs/prog2/info.json Normal file
View File

@@ -0,0 +1,8 @@
{
"name": "演習 2ー2",
"description": "2つの整数値を読み込み、それらの和と積を表示するプログラム。",
"output": {
"type": "screenshot",
"content": "./assets/prog2.png"
}
}

BIN
programs/prog2/main Executable file

Binary file not shown.

15
programs/prog2/main.c Normal file
View File

@@ -0,0 +1,15 @@
#include <stdio.h>
int main(void) {
int a;
int b;
printf("Integer a: ");
scanf("%d", &a);
printf("Integer b: ");
scanf("%d", &b);
printf("Sum of two integers is %d, and product is %d.", a+b, a*b);
return 0;
}

View File

@@ -0,0 +1,8 @@
{
"name": "課題4",
"description": "入力した三桁の正の整数の数字の並びを逆順させた数字を表示するプログラム。",
"output": {
"type": "screenshot",
"content": "./assets/rev3dig.png"
}
}

BIN
programs/rev3dig/main Executable file

Binary file not shown.

26
programs/rev3dig/main.c Normal file
View File

@@ -0,0 +1,26 @@
#include <stdio.h>
int main(void) {
int n;
printf("Integer n: ");
scanf("%d", &n);
// Throw error when n is not in range of 100 <= n <= 999
if (n < 100 || n > 999) {
printf("Integer n must be 3 digit number");
return 1;
}
int a, b, c, m; // a * 10^2 + b * 10^1 + c * 10^0 = n
a = n / 100;
b = n / 10 % 10;
c = n % 10;
m = c * 100 + b * 10 + a; // m is reversed n
printf("Reversed integer is %d.", m);
return 0;
}