Professional Documents
Culture Documents
CC213:Programming Applications: 1DA Revision
CC213:Programming Applications: 1DA Revision
CC213:Programming Applications: 1DA Revision
Week 02-part3
1DA
Revision
Arrays
• An array is an ordered list of values
The entire array Each value has a numeric index
has a single name
0 1 2 3 4 5 6 7 8 9
scores 79 87 94 82 67 98 87 81 74 91
2
The ScoresArray
3
Declaring and DefiningArrays
4
InitializingArrays
5
Note
One array cannot be copied to another using assignment.
6
Array Input/ Output
• We typically use for loops for any kind of array
processing.
• To input an array, one by one:
}
Example
• double X[ ]= {16.0, 12.0, 6.0, 8.0, 2.5, 12.0,
14.0, -54.5}
• int i=5;
• printf(“%f”, x[4]);
• printf(“%f”, x[i]+1);
• printf(“%f”, x[i+1]);
• printf(“%f”, x[2*i]);
Example
• double X[ ]= {16.0, 12.0, 6.0, 8.0, 2.5, 12.0,
14.0, -54.5}
• int i=5;
• printf(“%f”, x[2*i-3]);
• printf(“%f”, x[(int) x[4]]);
• printf(“%f”, x[i++]);
• printf(“%f”, x[--i]);
• x[i]= x[i+1];
Sample Problem