03.01.2015 Views

Complete set: Intro to C - Bill Buchanan

Complete set: Intro to C - Bill Buchanan

Complete set: Intro to C - Bill Buchanan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

inputValues = new double[5];<br />

which creates a new array with 5 elements (0 <strong>to</strong> 4).<br />

In Program 3.1 an array with 5 elements is created, after which the getValues()<br />

method is used <strong>to</strong> get these values from the user, after which the average() method<br />

is used <strong>to</strong> determine the average of the values. The v.Length property is used <strong>to</strong> determine<br />

the size of the array.<br />

Program 3.1: Program3_1_ArrayCalcAverage<br />

using System;<br />

namespace ConsoleApplication2<br />

{<br />

class ArrayExample01<br />

{<br />

static void getValues(double[] v)<br />

{<br />

int i;<br />

}<br />

for (i=0;i 1<br />

Value >> 2<br />

Value >> 3<br />

Value >> 4<br />

Value >> 5<br />

Average is 3<br />

Agilent .NET Course: Arrays and Collections 4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!