Upload
nicole-ynne-estabillo
View
59
Download
4
Embed Size (px)
Citation preview
The Character '\n' and the String “\n”
The compiler recognizes both '\n' and “\n” as containing the newline character. The difference is in the data type used. Formally, '\n' is a character literal, and “\n” is a string literal. From a practical standpoint, both cause the same thing to happen: A new line is forced in the output display.
Good programming practice requires ending the last output display with a newline escape sequence. This practice ensures that the first line of output from one program doesn’t end up on the last line displayed by the previously executed program.
A signed data type allows storing negative values, the value 0, and positive values
An unsigned data type provides for only non-negative values (that is, 0 and positive values). Some applications require only unsigned numerical values.
For example, many date applications store dates in the numerical form yearmonthday (storing 12/25/2011 as 20111225, for example)
For these applications, which never require a negative value, an unsigned data type can be used.
Floating-Point Types
A floating-point number, more commonly known as a real number, can be the number 0 or any positive or negative number containing a decimal point. The following are examples of floating point numbers:
+10.62 5.0 -6.2 3251.92 0.00 .33-6.67 +2.
A float value is sometimes referred to as a single-precision number and a double value as a double-precision number. 9.234 indicates a double literal.
9.234F indicates a float literal.
9.234L indicates a long double literal.
What is precision?
In numerical theory, the term precision typically refers to numerical accuracy.
“This computation is accurate, or precise, to the fifth decimal place” means the fifth digit after the decimal point has been rounded, and the number is accurate to within ±0.00005.
687.45678921 has five significant digits therefore; its accurate to have the value 687.46. The last digit assumed to be rounded.
In computer programming, “precision” can refer to a number’s accuracy or the number of significant digits; significant digits are defined as the number of clearly correct digits plus 1.
.000734 7.34e-4
7.34x10
-4.000000000954
Is it big number? Why?
67598934 6.7598934e7
6.7598934x107
Exponential Notation
Floating-point numbers can also be written in exponential notation, which is similar to scientific notation and is commonly used to express both very large and very small values in compact form. The following examples show how numbers with decimals can be expressed in exponential and scientific notation: