Lecture23

# Lecture23 - ECS 30 Introduction to Programming and Problem...

This preview shows pages 1–8. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: ECS 30 Introduction to Programming and Problem Solving Franois Gygi Department of Computer Science Lecture 23 Chapter 11 Using structured types Recursion example: print a sequence in reverse order Read integers from input, print them in reverse order input: 1 3 4 7 8 9 output: 9 8 7 4 3 1 program reverse.c Recursion example: print a sequence in reverse order Read integers from input, print them in reverse order void reverse(void) { read x; if EOF return; reverse(); print x; } program reverse.c Print a sequence in reverse order: iterative solution void reverse(void) { int x[maxsize]; int n = /* determine size n */ for ( i = 0; i &amp;lt; n; i++ ) read x[i]; for ( i = n-1; i &amp;lt;=0 n; i-- ) print x[i]; } Grouping variables Some variables are logically related /* position of a point in the plane */ double x; /* x coordinate */ double y; /* y coordinate */ /* define point 1 */ double x1, y1; /* define point 2 */ double x2, y2; Grouping variables These variables are used together /* compute the distance between two points */ double dist(double x1, double y1, double x2, double y2) { return sqrt((x1-x2)*(x1-x2)+ (y1-y2)*(y1-y2)); }...
View Full Document

## This note was uploaded on 01/21/2012 for the course ECON 2a taught by Professor Xi during the Spring '11 term at Cornell College.

### Page1 / 24

Lecture23 - ECS 30 Introduction to Programming and Problem...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online