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

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
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 image www.halloween-corner.com Lecture 17 No homework this week: prepare your midterm! Midterm topics: up to Lecture 17 (this lecture). Chapters 1-8.5 Questions/Answers session Friday Nov 4 Today: Chapter 8 Using arrays Using arrays Array: a collection of variables indexed by an integer double x[8]; Reserves space for 8 double variables x[0] /* first element of array */ x[1] /* 2 nd element */ ... x[7] /* last (eighth) element */ Using arrays int x[5]; x[0] x[1] x[2] x[3] x[4] Contiguous in memory Defining array sizes Array declaration (fixed size) double x[8]; Using a parameter for the array size Use a macro. (ok) #define SIZE 8 double x[SIZE]; Use a const int variable. (better) const int size = 8; double x[size]; program read_array.c Arrays as parameters Passing an array as a parameter to a function double sum(double x, int size) { int i; double s = 0.0; for ( i = 0; i < size; i++ ) s += x[i]; return s; }...
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 / 19

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online