the C language - 16B

logistic_guy

Senior Member
Joined
Apr 17, 2024
Messages
2,214
Write a program that asks the user to enter two numbers, obtains them from the user and prints their sum, product, difference, quotient and remainder.
 
\(\displaystyle \textcolor{green}{\text{\#include <stdio.h>}}\)

\(\displaystyle \textcolor{blue}{\text{int}}\) \(\displaystyle \bold{main}\)(\(\displaystyle \textcolor{blue}{\text{void}}\)){

\(\displaystyle \textcolor{blue}{\text{int}}\) integer1;
\(\displaystyle \textcolor{blue}{\text{int}}\) integer2;

\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"Enter the first integer: "}}\));
\(\displaystyle \textcolor{magenta}{\text{fflush}}\)(\(\displaystyle \textcolor{blue}{\text{stdout}}\));
\(\displaystyle \textcolor{magenta}{\text{scanf}}\)(\(\displaystyle \textcolor{green}{\text{"\%d"}}\), &integer1);

\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"Enter the second integer: "}}\));
\(\displaystyle \textcolor{magenta}{\text{fflush}}\)(\(\displaystyle \textcolor{blue}{\text{stdout}}\));
\(\displaystyle \textcolor{magenta}{\text{scanf}}\)(\(\displaystyle \textcolor{green}{\text{"\%d"}}\), &integer2);

\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"\textbackslash{}n\%d + "}}\), integer1);
\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"\%d = "}}\), integer2);
\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"\%d"}}\), integer1 + integer2);

\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"\textbackslash{}n\%d x "}}\), integer1);
\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"\%d = "}}\), integer2);
\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"\%d"}}\), integer1 * integer2);

\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"\textbackslash{}n\%d - "}}\), integer1);
\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"\%d = "}}\), integer2);
\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"\%d"}}\), integer1 - integer2);

\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"\textbackslash{}n\%d / "}}\), integer1);
\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"\%d = "}}\), integer2);
\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"\%0.2f"}}\), (\(\displaystyle \textcolor{blue}{\text{double}}\))integer1 / integer2);

\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"\textbackslash{}n\%d \% "}}\), integer1);
\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"\%d = "}}\), integer2);
\(\displaystyle \textcolor{magenta}{\text{printf}}\)(\(\displaystyle \textcolor{green}{\text{"\%d"}}\), integer1 % integer2);
}


\(\displaystyle \large\textcolor{indigo}{\bold{Sample.}}\)

programming_C.png
 
Last edited:
Top