Saturday, 31 December 2011
Where to download c++?????
You May Download C++ software in the link below.....
just click ob one of the link and follow the instruction.
The do…while Repetition Statement
- Example (letting counter = 1):
- do {
- printf( "%d ", counter );
- } while (++counter <= 10);
- Prints the integers from 1 to 10
Flowchart of the do…while repetition statement
example...
result...
Recursive Function
Definition....
Recursion: Factorials of nonnegative numbers
- A recursive function is one that calls itself repetitively until a final call is made thet no longer requires a self-call.
- Functions that call themselves
- Can only solve a base case
- Divide a problem up into
- What it can do
- What it cannot do
- What it cannot do resembles original problem
- The function launches a new copy of itself (recursion step) to solve what it cannot do.
- Eventually base case gets solved
- Gets plugged in, works its way up and solves whole problem.
Recursion: Factorials of nonnegative numbers
- Example: factorials
- 5! = 5 * 4 * 3 * 2 * 1
- Notice that
- 5! = 5 * 4!
- 4! = 4 * 3!......
- It can compute factorials recursively
- Solve base case ( 1! = 0! = 1) then plug in
- 2! = 2 * 1! = 2 * 1 = 2 ;
- 3! = 3 * 2! = 3 * 2 = 6 ;
Recursive Evaluation of 5!
Logical Operators
- && ( logical AND )
- Returns true if both conditions are true
- || ( logical OR )
- Returns true if either of its conditions are true
- ! ( logical NOT, logical negation )
- Reverses the truth/falsity of its condition
- Unary operator, has one operand
- Useful as conditions in loops
true && false false
true || false true
!false true
Truth table for the && (logical AND) operator.
Truth table for the logical OR (||) operator.
Truth table for operator ! (logical negation).
Operator Precedence and Associativity
The for Repetition Statement
- Format when using for loops
- for ( initialization; loopContinuationTest; increment )statement
- Example:
- for(counter = 1; counter <= 10; counter++ ) (No semicolon (;)
after last expression) - printf( "%d\n", counter );
- Prints the integers from one to ten
- For loops can usually be rewritten as while loops:
- initialization;
- while ( loopContinuationTest ) {
- statement;
- increment;
- }
- Initialization and increment
- Can be comma-separated lists
- Example:
- for ( i = 0, j = 0; j + i <= 10; j++, i++)
- printf( "%d\n", j + i );
Flowcharting a typical for repetition statement
example...
result...
Math Library Functions
- Math library functions
- Perform common mathematical calculations
- #include <math.h>
- Format for calling functions
- FunctionName( argument );
- » If multiple arguments, use comma-separated list
- printf( "%.2f", sqrt( 900.0 ) );
- » Calls function sqrt, which returns the square root of its argument
- » All math functions return data type double
- Arguments may be constants, variables, or expressions
Commonly used library functions
continue...
Repetition Essentials
- Loop
- Group of instructions computer executes repeatedly while some condition remains true
- Counter-controlled repetition
- Definite repetition: know how many times loop will execute
- Control variable used to count repetitions
- Sentinel-controlled repetition
- Indefinite repetition
- Used when number of repetitions not known
- Sentinel value indicates "end of data"
Subscribe to:
Posts (Atom)