98 lines
3.1 KiB
TeX
98 lines
3.1 KiB
TeX
\section{\texttt{int}型・\texttt{double}型と\texttt{printf}関数・\texttt{scanf}関数の書式}
|
|
|
|
\defaultlistingstyle
|
|
\lstinputlisting[language=C, title={変更前のソースコード}]{../programs/printf-formats/main.c}
|
|
|
|
上記のソースコードについて、\texttt{printf}関数と\texttt{scanf}関数の書式を次のように変更していく:
|
|
|
|
\begin{table}[h]
|
|
\centering
|
|
\begin{tabular}{lc}
|
|
\hline
|
|
\multicolumn{1}{c}{概要} & 実行ファイル名 \\
|
|
\hline \hline
|
|
第一の\texttt{printf}関数の書式を\texttt{\%f}にする & \texttt{main-p1-f} \\
|
|
第一の\texttt{printf}関数の書式を\texttt{\%lf}にする & \texttt{main-p1-lf} \\
|
|
第二の\texttt{printf}関数の書式を\texttt{\%d}にする & \texttt{main-p2-d} \\
|
|
第二の\texttt{printf}関数の書式を\texttt{\%lf}にする & \texttt{main-p2-lf} \\
|
|
第一の\texttt{scanf}関数の書式を\texttt{\%f}にする & \texttt{main-s1-f} \\
|
|
第一の\texttt{scanf}関数の書式を\texttt{\%lf}にする & \texttt{main-s1-lf} \\
|
|
第二の\texttt{scanf}関数の書式を\texttt{\%d}にする & \texttt{main-s2-d} \\
|
|
第二の\texttt{scanf}関数の書式を\texttt{\%f}にする & \texttt{main-s2-f} \\
|
|
\hline
|
|
\end{tabular}
|
|
\end{table}
|
|
|
|
\subsection{\texttt{main-p1-f}}
|
|
|
|
\begin{center}
|
|
\includegraphics[width=\textwidth]{./assets/printf-formats/main-p1-f.png}
|
|
\end{center}
|
|
|
|
\subsection{\texttt{main-p1-lf}}
|
|
|
|
\begin{center}
|
|
\includegraphics[width=\textwidth]{./assets/printf-formats/main-p1-lf.png}
|
|
\end{center}
|
|
|
|
\subsection{\texttt{main-p2-d}}
|
|
|
|
\begin{center}
|
|
\includegraphics[width=\textwidth]{./assets/printf-formats/main-p2-d.png}
|
|
\end{center}
|
|
|
|
\subsection{\texttt{main-p2-lf}}
|
|
|
|
\begin{center}
|
|
\includegraphics[width=\textwidth]{./assets/printf-formats/main-p2-lf.png}
|
|
\end{center}
|
|
|
|
\subsection{\texttt{main-s1-f}}
|
|
|
|
\begin{center}
|
|
\includegraphics[width=\textwidth]{./assets/printf-formats/main-s1-f.png}
|
|
\end{center}
|
|
|
|
\subsection{\texttt{main-s1-lf}}
|
|
|
|
\begin{center}
|
|
\includegraphics[width=\textwidth]{./assets/printf-formats/main-s1-lf.png}
|
|
\end{center}
|
|
|
|
\subsection{\texttt{main-s2-d}}
|
|
|
|
\begin{center}
|
|
\includegraphics[width=\textwidth]{./assets/printf-formats/main-s2-d.png}
|
|
\end{center}
|
|
|
|
\subsection{\texttt{main-s2-f}}
|
|
|
|
\begin{center}
|
|
\includegraphics[width=\textwidth]{./assets/printf-formats/main-s2-f.png}
|
|
\end{center}
|
|
|
|
\newpage
|
|
|
|
\subsection{結果}
|
|
|
|
\begin{table}[h]
|
|
\caption{実行結果一覧(強調行は正常結果)}
|
|
\centering
|
|
\begin{tabular}{|ccc|}
|
|
\hline
|
|
実行ファイル名 & コンパイル警告の有無 & 意図的な結果であるか \\
|
|
\hline \hline
|
|
\texttt{main-p1-f} & 有 & 否 \\
|
|
\rowcolor[HTML]{FFC702}
|
|
\texttt{main-p1-lf} & 無 & 然 \\
|
|
\texttt{main-p2-d} & 有 & 否 \\
|
|
\rowcolor[HTML]{FFC702}
|
|
\texttt{main-p2-lf} & 無 & 然 \\
|
|
\texttt{main-s1-f} & 有 & 否 \\
|
|
\texttt{main-s1-lf} & 有 & 否 \\
|
|
\texttt{main-s2-d} & 有 & 否 \\
|
|
\texttt{main-s2-f} & 有 & 否 \\
|
|
\hline
|
|
\end{tabular}
|
|
\end{table}
|