A number is said to be represented in scientific notation if it is in the form of:
number = s * (r^exp)
where number is the number in scientific notation, s is called the significand, r is the radix (or base), and exp is the exponent. The number is said to be in normal form when the significand meets the criteria:
1 <= s < r
This rule implies that, for decimal numbers with no leading zeros, the decimal point always occurs at the right of the first significant symbol.
Example:Number | Comment |
23.24 | Not in scientific normal form (SNF) since the base and the exponent are missing. |
23.24*10^0 | Not in SNF since the significand (23.24) is larger than the base |
2.324*10^1 | Is a number in SNF: the significand (2.324) is larger than 1 and smaller than 10, and it is multiplied by the base (10) raised at some power (1). |
For practical and historical reasons, numbers in scientific notation are entered in computers in a slightly different format: the base (understood to be 10) is replaced by a e or a E, and the caret sign (^) is omitted.
For computer purposes, a number like 23.24 will be represented as 2.324e1 in SNF. Note that the number may have a leading sign (+ or -), and that the exponent itself can have a sign. The same number (23.24) can also be represented as +2.324e+1 where both the sign of the number and the sign of the exponent are present.
Your program will read a string from standard input and will decide whether the string represents a number in SNF or not. Note that your program must make the decision regardless of whether the number is actually representable in the computer or not.
For instance 1.41421356237309504880168872420969807856963176679737e0 would be a perfectly valid input to your program; however, you never get this many significant bits in any common computer representation.
Depending on how you write your program you may be able to indicate an error as soon as the character is entered, or alse read the number when an EOL is found, and only then process the string.
If you like to think of programs as being something useful (beyond the learning experience), then you can imagine your program is part of a package which is used to train students in Computer Science: your program will then do part of the training which refers to number formats.
For each business day you turn in your project earlier you receive a
5% bonus. However, penalties increase by 5% as well. You can turn in your
assignment up to ten business days ahead of the deadline.
Example:
You may be asked to do a code review with your instructor.
(c) 1997, Virgil Bistriceanu | Last update: November 1, 1997 | The cs330 home page |