generated from kenryuS/report-temp
added program and result of cls09
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,68 @@
|
|||||||
|
\documentclass[xelatex,a4paper,11pt,ja=standard]{bxjsarticle}
|
||||||
|
|
||||||
|
\usepackage{tex/preamble}
|
||||||
|
\usepackage{tex/simple-title}
|
||||||
|
|
||||||
|
\reportauthor{柴田健琉}
|
||||||
|
\reporttitle{情報処理2 - 前期第9回課題}
|
||||||
|
\reportdate{2026年}{06月}{16日}
|
||||||
|
\turnindate{2026年}{06月}{16日}
|
||||||
|
|
||||||
|
\begin{document}
|
||||||
|
\simpletitle
|
||||||
|
|
||||||
|
\section{はじめに}
|
||||||
|
|
||||||
|
この課題のプログラムは以下の環境での動作が確認されている:
|
||||||
|
|
||||||
|
\begin{itemize}
|
||||||
|
\item{OS: NixOS 26.05 Yarara, Linux 7.0.12 x86\_64}
|
||||||
|
\item{CC: GCC 15.2.0}
|
||||||
|
\item{CFLAGS: \texttt{-g -O1 -Wall -Wpedantic}}
|
||||||
|
\item{デバッガ: GNU gdb (GDB) 17.1}
|
||||||
|
\end{itemize}
|
||||||
|
|
||||||
|
\section{課題1 - 演習10-1}
|
||||||
|
|
||||||
|
教科書の演習10-1の\texttt{adjust\_point}関数を作成する.
|
||||||
|
|
||||||
|
\lstinputlisting[language=C,caption={課題1のプログラム}]{./src/cls09/a1.c}
|
||||||
|
|
||||||
|
\newpage
|
||||||
|
|
||||||
|
\subsection{実行結果}
|
||||||
|
|
||||||
|
\begin{figure}[tbh]
|
||||||
|
\centering
|
||||||
|
\includegraphics[width=10cm]{./assets/cls09-a1.png}
|
||||||
|
\caption{課題1の実行結果}
|
||||||
|
\end{figure}
|
||||||
|
|
||||||
|
\section{課題2 - 演習10-2}
|
||||||
|
|
||||||
|
教科書の演習10-2の\texttt{increment\_date}と\texttt{decrement\_date}関数を作成する. なお, 閏年は考慮しないものとする.
|
||||||
|
|
||||||
|
\lstinputlisting[language=C,caption={課題2のプログラム}]{./src/cls09/a2.c}
|
||||||
|
|
||||||
|
\subsection{実行結果}
|
||||||
|
|
||||||
|
\begin{figure}[tbh]
|
||||||
|
\centering
|
||||||
|
\includegraphics[width=10cm]{./assets/cls09-a2.png}
|
||||||
|
\caption{課題2の実行結果}
|
||||||
|
\end{figure}
|
||||||
|
|
||||||
|
\section{課題3 - 演習10-3}
|
||||||
|
|
||||||
|
教科書の演習10-3の\texttt{sort3}関数を作成する.
|
||||||
|
|
||||||
|
\lstinputlisting[language=C,caption={課題3のプログラム}]{./src/cls09/a3.c}
|
||||||
|
|
||||||
|
\subsection{実行結果}
|
||||||
|
|
||||||
|
\begin{figure}[tbh]
|
||||||
|
\centering
|
||||||
|
\includegraphics[width=10cm]{./assets/cls09-a3.png}
|
||||||
|
\caption{課題3の実行結果}
|
||||||
|
\end{figure}
|
||||||
|
\end{document}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
include ../common.mk
|
||||||
|
|
||||||
|
PROJECT_NAME:=cls09
|
||||||
|
|
||||||
|
TGTS:=$(patsubst %.c,%,$(wildcard *.c))
|
||||||
|
|
||||||
|
all: $(TGTS)
|
||||||
|
|
||||||
|
%: %.c
|
||||||
|
@mkdir -p $(BUILD_PATH)/$(PROJECT_NAME)
|
||||||
|
$(CC) $(CFLAGS) $^ -o $(BUILD_PATH)/$(PROJECT_NAME)/$@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) -drf $(BUILD_PATH)/$(PROJECT_NAME)
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void adjust_point(int *n) {
|
||||||
|
if (*n < 0) {
|
||||||
|
*n = 0;
|
||||||
|
} else if (*n > 100) {
|
||||||
|
*n = 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int d = 0;
|
||||||
|
|
||||||
|
printf("Input integer: ");
|
||||||
|
scanf("%d", &d);
|
||||||
|
|
||||||
|
adjust_point(&d);
|
||||||
|
printf("Result: %d\n", d);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define BUFFSZ 32
|
||||||
|
|
||||||
|
const int DAYS_IN_MONTH[12] = {
|
||||||
|
31,
|
||||||
|
28,
|
||||||
|
31,
|
||||||
|
30,
|
||||||
|
31,
|
||||||
|
30,
|
||||||
|
31,
|
||||||
|
31,
|
||||||
|
30,
|
||||||
|
31,
|
||||||
|
30,
|
||||||
|
31
|
||||||
|
};
|
||||||
|
|
||||||
|
void increment_date(int *year, int *month, int *day) {
|
||||||
|
(*day)++;
|
||||||
|
|
||||||
|
if (*day > DAYS_IN_MONTH[*month - 1]) {
|
||||||
|
*day = 1;
|
||||||
|
(*month)++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*month > 12) {
|
||||||
|
*month = 1;
|
||||||
|
(*year)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void decrement_date(int *year, int *month, int *day) {
|
||||||
|
(*day)--;
|
||||||
|
|
||||||
|
if (*day < 1) {
|
||||||
|
(*month)--;
|
||||||
|
if (*month < 1) {
|
||||||
|
*month = 12;
|
||||||
|
(*year)--;
|
||||||
|
}
|
||||||
|
*day = DAYS_IN_MONTH[*month - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
char *buff = (char*)malloc(sizeof(char) * BUFFSZ);
|
||||||
|
|
||||||
|
int m, d, y;
|
||||||
|
printf("Input date in mm/dd/yyyy: ");
|
||||||
|
fgets(buff, BUFFSZ, stdin);
|
||||||
|
sscanf(buff, "%d/%d/%d", &m, &d, &y);
|
||||||
|
|
||||||
|
|
||||||
|
char opr_in;
|
||||||
|
while (1) {
|
||||||
|
printf("Select operation [+/-]: ");
|
||||||
|
opr_in = getc(stdin);
|
||||||
|
if (opr_in == '+') {
|
||||||
|
increment_date(&y, &m, &d);
|
||||||
|
printf("Tomorrow is %02d/%02d/%4d\n", m, d, y);
|
||||||
|
break;
|
||||||
|
} else if (opr_in == '-') {
|
||||||
|
decrement_date(&y, &m, &d);
|
||||||
|
printf("Yesterday was %02d/%02d/%4d\n", m, d, y);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
printf("Error: Please input correct operation mode.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void swap(int *a, int *b) {
|
||||||
|
int t = *a;
|
||||||
|
*a = *b;
|
||||||
|
*b = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sort3(int *x, int *y, int *z) {
|
||||||
|
if (*x > *y) swap(x, y);
|
||||||
|
if (*y > *z) swap(y, z);
|
||||||
|
if (*x > *y) swap(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int a,b,c;
|
||||||
|
|
||||||
|
printf("Input 3 integers separated by ',': ");
|
||||||
|
scanf("%d,%d,%d", &a, &b, &c);
|
||||||
|
|
||||||
|
sort3(&a, &b, &c);
|
||||||
|
|
||||||
|
printf("Result: %d, %d, %d\n", a, b, c);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user