1 2 request a value for a request a value for b 3 4 5

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ;B Return A End Finds the Min of 2 numbers This algorithm utilizes: a) Only Sequence a) Sequence and Selection a) Sequence and Iteration b) Sequence, Selection and Iteration What Tool(s) Does this Algorithm Use? 1. 2. 3. 4. 5. 6. 7. Request a value for A Assign 1 to B While A > 1 Assign A*B to B Assign A1 to A Return B End This algorithm utilizes: a) Only Sequence b) Sequence and Selection c) Sequence and Iteration d) Sequence, Selection and Iteration What Tool(s) Does this Algorithm Use? 1. 2. 3. 4. 5. 6. 7. Request a value for A Assign 1 to B While A > 1 Assign A*B to B Assign A1 to A Return B End Computes the factorial of A This algorithm utilizes: a) Only Sequence b) Sequence and Selection a) Sequence and Iteration a) Sequence, Selection and Iteration From Algorithms To Programs So far we have described a few algorithms in pseudocode. Pseudocode is fine for communicating algorithms between people but it is not precise enough to be used by a computer. Our Algorithms Must Be Written in a Programming Language A programming language has precise syntax (grammar) and semantics (meaning). An algorithm in a programming language is called a program. To be used by the machine it must be translated into a native language specific to the computer's CPU (central processing unit) called machine language. This translation is done by a compiler. Writing directly in machine language is taxing for humans because it is so rudimentary. Reading A C++ Program #include <iostream> using namespace std; int main ( ) { double x, y; cin >> x; y = x * 7; cout << y; return 0; } Reading A C++ Program Much of this program is scaffolding. int main ( ) Scaffolding is only { important insomuch as it double x, y; holds the program together cin >> x; and provides context for y = x * 7; the C++ compiler. cout << y; We will consider this part return 0; of the program later. } #include <iostream> using namespace std; Reading A C++ Program The remaining part of the code consists of only 4 lines. The code reads in a number and then writes the result of multiplying the number by...
View Full Document

This note was uploaded on 03/27/2008 for the course ENGR 101 taught by Professor Ringenberg during the Fall '07 term at University of Michigan.

Ask a homework question - tutors are online