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 DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full 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 &lt; n; i++ ) read x[i]; for ( i = n1; i &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((x1x2)*(x1x2)+ (y1y2)*(y1y2)); }...
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.
 Spring '11
 xi
 Macroeconomics

Click to edit the document details