Skip to main content
Engineering LibreTexts

7.5: Exercises

  • Page ID
    35833
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Exercise \(\PageIndex{1}\)

    Write the code to examine the value of the variable X. If it’s less than zero, the message negative value should be printed.

    Exercise \(\PageIndex{2}\)

    Write the code to examine the value of the variable X. If it’s equal to zero, the message zero value should be printed.

    Exercise \(\PageIndex{3}\)

    Write the code to compare the values of the variables X and Y. The greater value should be printed.

    Exercise \(\PageIndex{4}\)

    Write the code to examine the values of the variables X and Y. If both X and Y are greater than zero, increment X by one.

    Exercise \(\PageIndex{5}\)

    Write the code necessary to print the message Error! six times but without using six sequential printf() calls.

    Exercise \(\PageIndex{6}\)

    Write the code required to control a loop so that it continues so long as the variable K is less than 50.

    Exercise \(\PageIndex{7}\)

    Write the code needed to cycle the variable R from 100 to 200 in steps of 5 (i.e., 100, 105, 110, etc.).

    Exercise \(\PageIndex{8}\)

    Explain the practical difference between a while loop and a do-while loop.


    This page titled 7.5: Exercises is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by James M. Fiore via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.