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

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;
}