Session 06 Introduction to Programming

18 196 0
  • Loading ...
1/18 trang

Thông tin tài liệu

Ngày đăng: 08/10/2015, 22:23

Differentiate between Command, Program and SoftwareExplain the beginning of CExplain when and why is C usedDiscuss the C program structureDiscuss algorithmsDraw flowchartsList the symbols used in flowcharts LBC, Session 6ArrayFPT APTECH COMPUTER EDUCATION HANOI Objectives• Explain array elements and indices• Define an array• Explain array handling in C• Explain how an array is initialized• Explain string / character arrays• Explain two dimensional arrays• Explain initialization of two dimensional arraysLBC/Session 62 What is Array?• An array is a collection of data elements of the sametype.• Each element of the array has the same data type,same storage class and same characteristics.• These elements are known as members of the array.LBC/Session 63 Array Elements & Indices• Each member of an array is identified by unique index orsubscript assigned to it• An index is a positive integer enclosed in [ ] placedimmediately after the array name• An index holds integer values starting with zero• An array with 11 elements will look like:players[0], players[1], …, players[10]LBC/Session 64 Defining an Array-1.• An array has some particular characteristics and hasto be defined with them• These characteristics include:– Storage Class– Data Types of the elements in the Array– Array NameWhich indicates the location of the firstmember of the array– Array Sizea constant evaluating to a +ve valueLBC/Session 65 Defining an Array-2• An array is defined in the same way as a variable is defined.• The only change is that the array name is followed by one ormore expressions, enclosed within square brackets [],specifying the array dimension.storage_class data_type array_name[size]Example:int player[11];LBC/Session 66 Norms with Arrays•All elements of an array are of the same type•Each element of an array can be used wherever avariable is allowed or required•Each element of an array can be referenced using avariable or an integer expression•Arrayscanhavetheirdatatypeslike:int, char, float or doubleLBC/Session 67 Array Handling in C-1• An array is treated differently from a variable in C• Two arrays, even if they are of the same type and sizecannot be tested for equality• It is not possible to assign one array directly to another• Values cannot be assigned to an array on the whole,instead values are assigned to the elements of the arrayLBC/Session 68 Array Handling in C-2void main(){int ary[10];int i, total, high;for(i=0; i[...]... and columns • A two–dimensional array is declared as - int temp[4][3]; LBC /Session 6 11 Init of Multidimensional Arrays-1 int ary[3][4] = {1,2,3,4,5,6,7,8,9,10,11,12}; The result of the above assignment will be as follows : LBC /Session 6 12 Init of Multidimensional Arrays-2 int ary[3][4]= { {1,2,3}, {4,5,6}, {7,8,3} }; LBC /Session 6 13 Init of Multidimensional Arrays-3 The result of the assignment... in the following manner : char str_ary[25][80]; LBC /Session 6 14 Init array of string void main () { int i, n = 0; int item; char lines[10][12];char temp[12]; printf(“Enter each string on a separate line”); printf(“Type ‘END’ when over”); do { printf(“String %d : ”, n+1); scanf(“%s”, lines[n]); } while (strcmp(lines[n++], “END”)); / /to continue LBC /Session 6 15 reorder the list of strings /*reorder... */ strcpy (temp, lines[item]); strcpy (lines[item], x[i]); strcpy (lines[i], temp); } } } LBC /Session 6 16 Display the arranged list of strings /* Display the arranged list of strings */ printf(“Recorded list of strings : \n”); for(i = 0; i < n ; ++i) { printf("\nString %d is %s", i+1, lines[i]); } } LBC /Session 6 17 Summary • Define an array, element, index • Array handling in C • Initialization array... Define an array, element, index • Array handling in C • Initialization array • Explain string / character arrays • Explain two dimensional arrays • Explain initialization of two dimensional arrays LBC /Session 6 18 ... int temp[4][3]; LBC /Session 11 Init of Multidimensional Arrays-1 int ary[3][4] = {1,2,3,4,5,6,7,8,9,10,11,12}; The result of the above assignment will be as follows : LBC /Session 12 Init of Multidimensional... same storage class and same characteristics • These elements are known as members of the array LBC /Session Array Elements & Indices • Each member of an array is identified by unique index or subscript... with zero • An array with 11 elements will look like: players[0], players[1], …, players[10] LBC /Session Defining an Array-1 • An array has some particular characteristics and has to be defined
- Xem thêm -

Xem thêm: Session 06 Introduction to Programming, Session 06 Introduction to Programming, Session 06 Introduction to Programming

Từ khóa liên quan

Gợi ý tài liệu liên quan cho bạn