Objectives of This Chapter
|
|
- Eugenia Goodwin
- 6 years ago
- Views:
Transcription
1 Chapter 6 C Arrays
2 Objectives of This Chapter Array data structures to represent the set of values. Defining and initializing arrays. Defining symbolic constant in a program. Using arrays to store, list, and search the set of values in an array. Defining and working with multiple subscripted arrays.
3 Introduction to Arrays Most of the programming languages provides capability to define set of variables (data items) known as arrays. Use of arrays is an important topic for data structures (2 nd year course). Data means collection of related items (Chapter 10). Arrays also takes up space in the memory as regular variables. Most of the time, this space is limited and can not be changed throughout the program. Chapter 12, we will learn about creating set of variables (arrays) whose sizes may increased or shrunk as needed. Example: Exam results for a Class Set of variables holding the exam results for bunch of students. If you try to sort them, probably it is likely impossible to do without using arrays.
4 Defining Arrays in C Defining an array in C is very similar to defining a single variable, but for arrays we do also give the size in the square brackets. type name_of_the_array[size]; Example: int c[12] ; /*Creates an array with 12 elements*/ The elements of this array: c[0], c[1],. c[10],c[11] Position number in the brackets called index or subscript. Each element in an array is like a single variable, has integer type with 4 byte. Operations with the elements of the array is similar to operation with single variable: c[0]= 45; /*Assign 45 value to 1 st element of the array*/ c[5]++ ; /*Increase the 6 th element by +1*/
5 Example: Operations with Arrays Assume that we have an array named c with size of 12. Assume also that the elements initialized/assigned by values Values stored in each array is shown on the right. What do the following operations do? c[10]=553; c[5]++; a=1; b=3; x=(c[a]+c[b])/2; printf( %d,x); c[a+b]=c[a]+c[b]; printf( %d%d%d,c[a],c[a]+c[b],c[5]);
6 Example: Initializing Elements of an Array to zero p. 230 Write a program. In this program, you define an integer type of array named n with 10 elements. Then assign zero to each elements in the array. Then list them out in tabular form along with the indices.
7 More on Initializing Elements of an Array There are different ways to assign an initial value to elements of an array. Let s consider the integer type of n[10] array. int n[10]={0}; /*Initialize all elements to 0 */ int n[10]={3}; /*Initialize n[0] to 3 then rest to 0 */ int n[10]={10,15,16,17,24,23, 10,9,0}; /*this is called list initialization*/ means n[0]=10, n[1]=15, n[9]=0 /*list on the right called initialization list*/ int n[10]={1,4,6}; /*Initialize only first three elements to the values in the list then rest to 0 */ int n[10]={[7]=1,[3]=2}; /*Initialize only 8 th and 4th elements to given values and rest to 0 */ What happens if we don t define the size in the brackets? int n[]={1,5,6,4,3}; int m[]={3,5,7}; int x[]={7,5,6,4}; Sizes are automatically assigned as the number of elements given in the initialization list.
8 Example: Generating Fibonacci Numbers Write a program that generates first 15 Fibonacci numbers and store them in an array called Fibonacci. At the end of the program it should print the calculated Fibonacci numbers along with the indexes. Remember: Definition of Fibonacci Numbers Fibonacci[0]=0; Fibonacci[1]=1; and Fibonacci[n]=Fibonacci[n 1]+Fibonacci[n 2]; for n 2
9 Example: Rolling Dice 100 Times Write a program that rolls dice (using rand function) for 100 times. This program will determine how frequently (how many times) 1, 2, 3 6 faces appears and keeps these numbers in an array named frequency. Then prints the results in the following tabular form with Histogram. Below is an example output of the program when executed: Face Frequency Histogram 1 14 ************** 2 16 **************** 3 22 ********************** 4 8 ******** 5 24 ************************ 6 16 **************** Page 186
10 Using #define to define a symbolic constant #define NAME value Expression are called preprocessor directives. Are used at the beginning of the program after #include preprocessor directives. These are used to define constant values. Unlike regular variables, these values doesn t take any space in the memory. The compiler comes and replace the NAME in the program by the value before it start to compile. More details on C preprocessor directives are given in Chapter 13.
11 Using Character Arrays to Store and Manipulate Strings p 239 Collection of characters is called as STRING. Example: Gaziantep / Turkey So far, we have only seen %s in printf to print out a string to the screen. printf ( %s, Ali ); In programming, a string can be considered as a character array. char a[20]; or char name[10], last_name[10]; char name[10]: Has 10 elements from c[0] to c[9] But it can hold maximum 9 characters, because the last element in the name array is used as termination character which is null character. Null character value in Ascii table is \0 String termination character is placed at the end of the character arrays/strings. This helps programmer to deal with the string more efficiently. This helps us to determine the end of the string.
12 Initialization and Operations with String Variables p 239 char string[]= first ; /*creates string with 6 elements*/ Element string[0] string[1] string[2] string[3] string[4] Stored Value f i r s string[5] \0 t Initialization can be also done using initialization list: char string[] = { 'f', 'i', 'r', 's', 't', '\0' }; This is character by character initialization. also possible to define then READ IT FROM KEYBOARD A string can also be first defined then read from the keyboard. In this case the size of the string must be determined in the identifier line. char string[20]; /* Creating String that can hold 19 Character*/ printf( Enter the First String ); scanf( %s,string); /* Reading string value from keyboard no &*/ Note: We don t use & while reading string, this is because the name of a string array holds the memory address of the string array.
13 Example: Program finding the length of a string Write a program which takes a string from keyboard then the program prints the length of the string to the screen. Below is an example output of the program when executed: Enter a string: COMPprog Length of the string: 8
14 Example: String Reading and Printing Write a program that has two string variables; string1 is defined with size of 20 and string2 is initialized to store Welcome to Gaziantep. In your program stgring1 will be read from keyboard after prompting the user with Enter a String:. Then your program will print the followings to the screen: string1 characters in string1 (one character in a one line) sting2 characters in string2 (one character in a one line)
15 Example: Printing the a string in character reversed order Write a program that reads a string from screen then it prints to the screen in reversed order. Below is an example output of the program when executed: Enter a string: Welcome to Gaziantep Your string reversed: petanizag ot emoclew
16 Static Local and Automatic Local Arrays Similar to local or global variables; arrays can be also defined local or global. If the array is defined before the main program, this array becomes a global array and can be accessible from everywhere in the program (program scope). Arrays created in the functions are created and destroyed every time the function is invoked. If an array in a function defined as static int a[20]; similar to the static variables, this array is created only once not destroyed at the end of function. The concept is exactly the same as the variables (Chap 5.).
17 Passing Arrays to a Functions In order to pass an array to a function, we write only the name of the array without brackets. Example: Assume we have hourlytemperature array defined as below and passed to a function called my function Main program: int hourlytemperature[24]; myfunction (hourlytemperature, 24); Function: void myfunction (int b[], int size){ } Note: As you may notice, also the size of the array is sent to function to inform about the size of it if needed. While we are passing string arrays; because the last value in a string is \0 (null character), we don t need to also pass the size as we do other type of arrays.
18 More on Passing Arrays to a Functions Unlike passing regular variables, passing arrays to a function is callby reference type. Remember: Call by value and Call by reference Call by value: Function can t do any change on the variable. Call by reference: Function can change the variable/array. While passing array to a function is a call by reference call? Because name of the array hourlytemplate refers to the memory addresses allocated for elements of the array. So that the function can do the change directly on the memory address allocated for the array. How can we do a call by value while passing arrays to a function? This is only possible by sending individual elements of the array. myfunction(a[0],a[1], ); but this is less practical. Or in the function s argument, we define the array as constant array. void myfunction ( const int b[],size) /*so the function can t change */
19 Page 245 Example: Array name refers to the memory addresses for the array The following program prints the memory address for an array
20 Example: Function sums the elements of an integer array Write a function named sum which is called from main program to find the sum of the elements of an integer array. The function will return the sum of the elements to the caller at the end of the function.
21 Example: Function to find the length of a string Write a function which determines the length of the string variable. Call this function from your main program to find the length of a string. The function receives the string from the caller and it returns the length of the string to the caller at the end. Below is an example output of the program when executed: Enter a string: COMPprog Length of the string: 8
22 Example: Passing an Array to a Function and an Element p.247 Write a program in which define an integer type of array defined as numbers[]={0,1,2,3,4}. Your main program calls a function called multiplyarray which multiples the each element in the array by 2. Then it calls another function named multiplyelement by passing only number[3] (4th element) and this function also multiply it by 2. Print out the array at the beginning of the program and after each calls of functions.
23 Example: Finding Maximum in an Array Write a complete C program in which define an integer type of integer named numbers and size of 10; numbers[10]. The elements of the numbers array are generated as random numbers using rand() within the range of 1 to 1000 from stdlib C library. After assigning random values to each elements, the program calls a function printarray that prints out the array. Finally, it calls a function called maxarray which finds the maximum number in the number array and the main program finish the program by printing this maximum value.
24 Example: Statistical Computations Using Arrays Write a C program that computes the mean (average) and standard deviation of an array data with size of 8. Then the program displays computed mean value, standard deviation, and the difference between each value and the mean value as shown in the figure. Below is an example output of the program when executed: Enter 8 Numbers: The mean is The standard deviation is Index Number Difference Reminder: Statistical Definitions mean SIZE 1 i 0 SIZE 1 x SIZE i i 0 2 std _ dev mean x SIZE i 2
25 Putting set of numbers/characters in ascending or descending order are called as sorting. Sorting is one the most important application of programming. p 242 So far, we have learned sorting of a few variables as like x, y, z variables. Let s assume: x=1; y=7; z=2 Ascending order of these numbers : 1, 2, 7 (Ascending = Getting Higher) Descending order of these numbers: 7, 2, 1 (Descending = Getting Lower) Sorting can be accomplished by comparing numbers with one another then swapping if needed. Sorting task gets complicated if you have too many numbers to deal with, for example, balances of the costumers in a bank, their credit limits, due dates for the next payment, and so on.
26 Continues p 242 Sorting of large amount of quantities can be done using arrays. First we load the numbers/quantities to array then sort the array in the order we want. Example: Sorting Array with size of 5: Before Sorting Element Stored Value num[0] 89 num[1] 65 num[2] 121 num[3] 10 num[4] 3 After Sorting in Ascending Order Element Stored Value num[0] 10 num[1] 3 num[2] 65 num[3] 89 num[4] 121 After Sorting in Descending Order Element Stored Value num[0] 121 num[1] 89 num[2] 65 num[3] 3 num[4] 10 Sorting can be done going through each element and compare them with one another.
27 Algorithms p 248 Sorting of arrays can be done going through each element and compare one element with another element and put them in the order which needed. There are different algorithms to sort arrays. Here we will only study two methods Bubble Sort (Sinking Sort): Most commonly used sorting algorithm. Name is associated with the bubbles goes up in a liquid while the heavier ones sink down. Selection Sort: Another commonly used sorting algorithm. In both algorithms, pair of elements are compared and arranged in the desired orders.
28 Sorting of Arrays BUBBLE SORT: p 248 In Bubble Sort, successive elements in an array are compared and swapped in the order desired. This process is repeated number of the items. Successive elements : a[i] and a[i+1] If they are in order then do nothing leave them as they are If they are not in order then swap the values (Remember we learned how to swap two values of variable analogy to swapping two glasses of water) This comparison must be done for all elements of the array, so the i value will be starting from 0 and run up to SIZE 1. The whole process will be repeated as many times as the SIZE 1 of the array. In conclusion, the part of C program for bubble sort is given below for (repeat=0 ; repeat < SIZE 1 ; repeat++){ //Repeating whole Process SIZE 1 TIMES for (i=0; i < SIZE 1; i++){ /*Going through each element FIRST TO THE LAST*/ Compare and swap the a[i] and a[i+1] elements if needed. } }
29 Two Glasses of Waters Analogy to Swapping Elements in Computation Let s assume, we have two glasses of drinks in different colors. We would like to swap/replace the content of one glass to another glass without mixing them. Shall we pour the drinks directly from one to another one? OR This doesn t work it, because destroys/mixes the contents.
30 Swapping Content of Glasses What if we have a Third Empty Glass We can accomplish this task using a third empty glass in three steps. 1 This will make Before 2 This will make After 3 This will make
31 Swapping Two Variable or Elements of an Array Swapping two variable or elements of an array requires a third dummy variable similar to empty glass. It can be done in the following case Swapping a and b variables: int a= 7, b=4, hold; /*Hold is the dummy Variable representing the empty glass*/ hold = a; /*First saving the value of a in the hold dummy variable*/ a = b; /*Putting value of b into a*/ b = hold; /*Putting value of hold into b*/ Eventually a becomes 4 and b becomes 7. Swapping Successive elements of an Array a: a[i] and a[i+1] hold = a[i]; a[i] = a[i+1]; a[i+1] = hold; Eventually value of a[i] and value of a[i] interchanged. This procedure will be used while swapping the elements of an array in sorting process if needed.
32 Sorting of Array a in Ascending Order BUBBLE SORT p 249 Terminal Output Of the Program Swapping Elements
33 Sorting of Arrays SELECTION SORT: Algorithm Out of Book In Selection Sort, starting from the first element, the element is compared with the rest of elements in the array and swapped in the desired order. This can be achieved by using nested for repetitions similar to bubble sort. The loops should be constructed as shown below, for (i=0; i < SIZE-1; i++){/*ith element to be compared*/ for (j=i+1; j < SIZE; j++){ /*jth element to be compared notice j > i */ Compare and swap the a[i] and a[j] elements if needed. } } By the end of each i loop, the smallest or maximum element among the i to the SIZE 1 is placed to i th element of the loop.
34 Sorting of Arrays SELECTION SORT: Pictorial Rep. Out of Book Pictorial representation of selection sort of an array with 6 elements in ascending order is shown below. for ( i=0; i < 5; i++) { /* Picks the element to be compared*/ for (j=i+1; j < 6; j++){ /*jth scans the rest of the elements notice j > i */ if (a[i] < a[j]) { /*Swapping the elements if necessary. hold= a[i]; a[i]= a[j]; a[j]=hold; } } /*loop for j finishes here */ } /*loop for i finishes here */
35 Comparison of Bubble Sort and Selection Sort Bubble Sort for (repeat=0 ; repeat <= SIZE 1 ; repeat++){ /*Repeating whole Process*/ for (i=0; i < SIZE 1; i++){ /*Going through each element*/ Compare and swap the a[i] and a[i+1] elements if needed. }} Number of Comparison: (SIZE 1) 2 Selection Sort for (i=0; i < SIZE 1; i++) { /*ith element to be compared*/ for (j=i+1; j < SIZE; j++){ /*jth element to be compared notice j > i */ Compare and swap the a[i] and a[j] elements if needed. }} Number of Comparison: SIZE*(SIZE 1)/2 Example: If size of array is 10 Bubble Sort does (10 1) 2 = 81 operations to sort out the data. Selection Sort does 10*(10 1)/2 = 45 operations to sort out the data. In conclusion, selection sort exhibits better performance in most cases. There are also other more complex sorting techniques far better in performance, but they are out of scope of this lecture.
36 Example: Bubble Sort and Selection Sort Descending Order Write a C program in which we define integer type of arrays numa and numb with size of 10. Values of numa and numb will be same and determined randomly within the range of 1 to 10. The program then prints these arrays to screen, then numa will be sent to bublesort function which will sort this array using bubble sort algorithm. numb will be sent to sent to a function named selectionsort where the array will be sorted based upon the selection sort algorithm. By the end of the program print the sorted arrays to screen. Note: Because, we are printing an array several times, it is good to use a function named printarray to do this task. Below is an example output of the program when executed: Before Sorting: numa: numb: After Sorting: numa: numb:
37 Page 251 Analysis of observed data are extensively used for statistical purposes. As like the analysis of results of a survey given to bunch of participators. These analysis includes the sorting of obtained data and determining the frequency of the same results. Then do the analysis using the quantities given below. Following Quantities are Important for Statistical Purposes: Mean: In other word, average value of the data set. Median: In a sorted data, Median value is the value of middle element. Mode: Value repeated most frequently. Study 6.7 Case Study Program at Page 252 yourself.
38 Example: Mean, Median, and Mode of Series Determine the Mean, Median, and Mode of Series for the following series. Before Sorting Index Number Sorted Index Number Mean: 5.64 (Sum of Numbers / # of Elements) Median: 6.00 (Middle Element in sorted Data) Mode: 8.00 (Most Frequent) In this example, number of elements is 11, so the middle value is the 6 th element gives us the median value. If the number of elements are even then two elements will be the middle elements, in this case the median value will be the average of the numbers. For instance, if SIZE=10 then the median is the average of 5 th and 6 th element.
39 We often work large amount of data and sometimes want to know if it includes a specific value with certain key. Page 255 In order to find the specific value, we need to go through the elements and compare them with the key value. The process of finding a particular element matching certain criteria is called searching. Various algorithms were developed to accomplish searching process. Here, we will only cover two methods. Linear Search : Can be applied to any data. Binary Search : Only applied to sorted data, more efficient.
40 The Linear Search compares each element in the array with the search key. Page 255 Once the value matching search key is found, the index of the element holding this value is used and searching process terminates. This process, is not very efficient in time of process. Worst Case Scenario: Last element is the searching value. Best Case Scenario: The first element is the searching value. Therefore, the number of comparison needs to be made is N/2. C code that find the key in an array named a with size of SIZE is given below. Initially value variable is set to -1. for ( n = 0; n < size; ++n ){/*loop through array */ if ( a[ n ] == key ) { value = n; break; /* terminate the repetition when found */ } /* end if */ } /* end for */
41 Page 255 linearsearch function is used to find the index Accepts three arguments: Array: Array within it search will be done. Key value: what to search for. Size of the Array. Returns the index of searched item. If the item can t be found, returns 1 Output of the Program As follows:
42 The Linear Searching method is sufficient for small or unsorted arrays. However, it is not efficient in sorting large arrays. Page 257 Binary Searching method can be used to search large and sorted arrays. Binary Search: Data is split into two halves. Key value is compared with the middle element. If the middle element matches, the searching process terminates by returning the index value. If the key value is greater than the middle element then the sub array is searched, or if the key value is smaller then the upper array is searched. This process continues until the searched value is returned in the array. This process is very efficient in time of process. Consider searching Array with size of Linear Search : Requires 1024/2 comparison in average. Binary Search: Requires 10 comparison at worst scenario (Notice: 2 10 =1024)
43 Implementation of Binary Search In order to understand how we can do the Binary search in a sorted array, let s consider that we are searching for a search key in a set of data sorted in ascending order Sorted Array Index Value Procedure is as the followings: Define two variables called low and high Low and High variables determines the boundaries in which the search Initially, low =0 and high = size 1 (first and last elements) Define the third variable middle as the middle element of this range middle = (low + high) / 2 Compare the value of middle element with search key: If the middle element equals to search key DONE! If the middle element is bigger start searching the lower region redefine high = middle 1 (shifting down the high to lower region If the middle element is bigger start searching the upper region redefine low = middle + 1 Repeat this process until finding the search key. Repeat the process as long as low <= high if not found, which means key doesn t exist in the array.
44 Example: Binary Search See also Page Fig 6.19 Page 258 Write a C program in which we define integer type of array named numbers with size of 20. The values are generated as numbers[i]=2*i where i is the index number of the array. Now, design a function named binarysearch which does the searching of a key. If the search key found, it returns the index/subscript number of the array matching the search key value. If the search key not found, it returns 1. In the main program, user will be asked to enter the search key value then it calls binarysearch to determine the index/subscript matching the entered key value. The main program prints out the index value determined by the function to the screen or printing Key Value. Not Found! if it is not found.
45 So far, we dealt with arrays with only one subscript numbers[10], str[20], a[100], etc. These arrays are called as single subscripted/one dimensional arrays. Single subscripted arrays are useful to understand the fundamental idea Also, they are sufficient to study simple problems. Page 261 In daily life applications, programs have more complexity and usage of onedimensional arrays might not be sufficient. In C language, it is possible to define arrays with more then one subscript. int a[3][4],char str[10][30], etc. (these are double subscripted arrays) Arrays with more than two subscripted are called multi subscripted arrays. Double subscripted arrays are commonly used in complicated real life programs.
46 Page 261 Let s Consider that we define a double subscripted array with dimension of 3 by 4. int a[3][4]; This will create array named a with 3x4 = 12 elements as shown below. Elements of this array are: a[0][0], a[0][1],a[0][2], a[0][3],.. a[2][0], a[2][1],a[2][2], a[0][3] Each element is like an int type of variable takes 4bit of space in the memory.
47 Usage of Double Subscripted Arrays In order to understand benefits of usage of double subscripted arrays. Let s consider the int exam_results[10][3]; 10 row by 3 column array with loaded with some values Rows Columns Array exam_results This array can be considered as three exam results of a class with 10 students. If so; Row index represents the student. Column index represents the exam. So then; exam_results[0][1] is the exam 1 result for the 1 st student. exam_results[8][2] is the exam 3 result for the 9 th student. This could also be done by defining three different arrays named exam1[10], exam2[10], and exam3[10] but would be less efficient if you would have 10 exams (many columns to deal with).
48 Example: Initialization of Double Subscripted Array Page 258 Let s consider the following lines in a C program In these three lines, double subscripted integer arrays a, b, and c with size of 2 row by 3 column are created and some of the elements are initialized. int a[ 2 ][ 3 ] = { { 1, 2, 3 }, { 4, 5, 6 } }; After Initializing Array a [0][0] [0][1] [0][2] [1][0] [1][1] [1][2] int b[ 2 ][ 3 ] = { 1, 2, 3, 4, 5 }; Array b [0][0] [0][1] [0][2] [1][0] [1][1] [1][2] After Initializing Array a Array b int c[ 2 ][ 3 ] = { { 1, 2 }, { 4 } }; Array c [0][0] [0][1] [0][2] [1][0] [1][1] [1][2] After Initializing Array c
49 Example: Initialization of Double Subscripted Array Page 258 Let s now consider the usage of double subscripted character arrays. char city[5][10]={"gaziantep","istanbul","chicago","paris", Mecca"}; Double subscripted character array (5 x 10) named city is defined and initialized to the city names given in the list. It can store up to 5 strings. Each string can have maximum of 9 characters (one for `\0`) [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] city[0] city[1] city[2] city[3] city[4] [0] [1] [2] [3] [4] 'G' 'a' 'z' 'i' 'a' n' 't' 'e' 'p' '\0' 'I' 's' 't' 'a' 'n' 'b' 'u' 'l' '\0' 'C' 'h' 'i' 'c' 'a' 'g' 'o' '\0' 'P' 'a' 'r' 'i' 's' '\0' 'M' 'e' 'c' 'c' 'a' '\0' Here reserved space for each string is 10 but some of them are not used.
50 Example: Multiple Strings Double Subscripted Char Array The following program keeps track of the name of 5 persons, the names are initialized within the program. Then it lists the 5 names. #include<stdio.h> int main (void){ char str[5][10]={"ali","veli","mehmet","yakup","veysel"}; int i; //Defined as counter to go through each string // Following line can be used to read in the names from keyboard instead of initializing //for ( i =0 ; i < 5 ; i++) {printf("enter the %dth name:",i); scanf("%s",str[i]);} for ( i =0 ; i < 5 ; i++) printf("%2dth name:%10s\n",i+1,str[i]); return 0; } Output of the Program:
51 Summary of Multi Subscripted Arrays In Summary, benefits of using multi subscripted arrays Easier to work with data with many column values In single subscripted arrays, for each column we need to define a separate array, this sometimes becomes impossible. Defining arrays capable of holding multiple strings is only possible with usage of double subscripted character arrays. In single subscripted arrays, for string we need to define a separate character array, this sometimes becomes impossible. Matrix operations in math is easy to handle by define doublesubscripted arrays. There are algorithms to handle such matrix operations by using singlesubscripted arrays but efficient only for special matrices (like symmetric ones).
52 Page 275
53 Page 276
54 Page 283
55 Page 283
56 Matrix Operations in C Programming Array of numbers arranged in rows and columns as rectangular form are called matrix (plural matrices) in mathematics. The individual items in a matrix are called its elements or entries. An example of a matrix A and matrix B with 3 rows and 3 columns is given below: A B Matrices have many applications in most scientific fields. In computer programming, a matrix can be stored in a double subscripted arrays. Most common mathematical operations with matrices are as below: Transpose of a Matrix Basic Math Operations of Matrices (summation subtraction) Multiplication of Matrices Determinant of Matrix. Here, we will only deal with the transpose and summation operations.
57 Transpose of a Matrix Example Transpose of a matrix is the obtained by swapping rows by columns. Matrix A and transpose of A, A T is shown below; A T A Example: Write a C program that calculates the transpose of a 5 row by 5 column matrix then prints matrix and it s transpose to screen. The elements of the matrix are generated as random number from 10 to 10, inclusively. You may answer the problem, by considering one 5x5 array and do the swapping between elements or by considering two arrays 5x5 and use the first array for the matrix and second array for it s transpose.
58 Basic Math Operations with Matrices Summation and subtraction of matrices are another matrices with the same size. In matrix sum./subt. operations, elements with the same subscripts are operated, giving the element with the same subscript of resulting matrix A B For A and B matrices given above, A+B and A B are given below; A B A B Example: Write a C program that sums and subtracts a 5 row by 5 column matrices and prints the results to screen. Elements of matrices are internally generated as random number from 10 to 10, inclusively. Generated matrices, sum matrix, subtraction matrix are printed to screen in square form as shown above
C How to Program, 7/e by Pearson Education, Inc. All Rights Reserved.
C How to Program, 7/e This chapter serves as an introduction to data structures. Arrays are data structures consisting of related data items of the same type. In Chapter 10, we discuss C s notion of
More informationProgramming for Engineers Arrays
Programming for Engineers Arrays ICEN 200 Spring 2018 Prof. Dola Saha 1 Array Ø Arrays are data structures consisting of related data items of the same type. Ø A group of contiguous memory locations that
More informationC Arrays. Group of consecutive memory locations Same name and type. Array name + position number. Array elements are like normal variables
1 6 C Arrays 6.2 Arrays 2 Array Group of consecutive memory locations Same name and type To refer to an element, specify Array name + position number arrayname[ position number ] First element at position
More informationLecture 04 FUNCTIONS AND ARRAYS
Lecture 04 FUNCTIONS AND ARRAYS 1 Motivations Divide hug tasks to blocks: divide programs up into sets of cooperating functions. Define new functions with function calls and parameter passing. Use functions
More informationC Arrays Pearson Education, Inc. All rights reserved.
1 6 C Arrays 2 Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end:
More informationIntroduction to Computer Science Midterm 3 Fall, Points
Introduction to Computer Science Fall, 2001 100 Points Notes 1. Tear off this sheet and use it to keep your answers covered at all times. 2. Turn the exam over and write your name next to the staple. Do
More informationChapter 4 - Arrays. 4.1 Introduction. Arrays Structures of related data items Static entity (same size throughout program)
Chapter - Arrays 1.1 Introduction 2.1 Introduction.2 Arrays.3 Declaring Arrays. Examples Using Arrays.5 Passing Arrays to Functions.6 Sorting Arrays. Case Study: Computing Mean, Median and Mode Using Arrays.8
More informationPrinciples of Programming. Chapter 6: Arrays
Chapter 6: Arrays In this chapter, you will learn about Introduction to Array Array declaration Array initialization Assigning values to array elements Reading values from array elements Simple Searching
More informationChapter 4 - Arrays. 4.1 Introduction. Arrays Structures of related data items Static entity (same size throughout program) A few types
Chapter 4 - Arrays 1 4.1 Introduction 4.2 Arrays 4.3 Declaring Arrays 4.4 Examples Using Arrays 4.5 Passing Arrays to Functions 4.6 Sorting Arrays 4.7 Case Study: Computing Mean, Median and Mode Using
More informationCS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017
CS 137 Part 8 Merge Sort, Quick Sort, Binary Search November 20th, 2017 This Week We re going to see two more complicated sorting algorithms that will be our first introduction to O(n log n) sorting algorithms.
More informationChapter 7 C Pointers
Chapter 7 C Pointers Objectives of This Chapter Definition and Operations with Pointers Using Pointers to pass arguments as call by reference call. Using Pointers to deal with arrays and strings. Character
More informationC++ PROGRAMMING SKILLS Part 4: Arrays
C++ PROGRAMMING SKILLS Part 4: Arrays Outline Introduction to Arrays Declaring and Initializing Arrays Examples Using Arrays Sorting Arrays: Bubble Sort Passing Arrays to Functions Computing Mean, Median
More informationChapter 5 C Functions
Chapter 5 C Functions Objectives of this chapter: To construct programs from small pieces called functions. Common math functions in math.h the C Standard Library. sin( ), cos( ), tan( ), atan( ), sqrt(
More informationHigh Institute of Computer Science & Information Technology Term : 1 st. El-Shorouk Academy Acad. Year : 2013 / Year : 2 nd
El-Shorouk Academy Acad. Year : 2013 / 2014 High Institute of Computer Science & Information Technology Term : 1 st Year : 2 nd Computer Science Department Object Oriented Programming Section (1) Arrays
More informationComputer Science & Engineering 150A Problem Solving Using Computers
Computer Science & Engineering 150A Problem Solving Using Computers Lecture 06 - Stephen Scott Adapted from Christopher M. Bourke 1 / 30 Fall 2009 Chapter 8 8.1 Declaring and 8.2 Array Subscripts 8.3 Using
More informationLecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)
Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays) In this lecture, you will: Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of
More informationArrays. Defining arrays, declaration and initialization of arrays. Designed by Parul Khurana, LIECA.
Arrays Defining arrays, declaration and initialization of arrays Introduction Many applications require the processing of multiple data items that have common characteristics (e.g., a set of numerical
More informationWrite a C program using arrays and structure
03 Arrays and Structutes 3.1 Arrays Declaration and initialization of one dimensional, two dimensional and character arrays, accessing array elements. (10M) 3.2 Declaration and initialization of string
More informationSubject: Computer Science
Subject: Computer Science Topic: Data Types, Variables & Operators 1 Write a program to print HELLO WORLD on screen. 2 Write a program to display output using a single cout statement. 3 Write a program
More informationMultiple-Subscripted Arrays
Arrays in C can have multiple subscripts. A common use of multiple-subscripted arrays (also called multidimensional arrays) is to represent tables of values consisting of information arranged in rows and
More informationB. V. Patel Institute of Business Management, Computer & Information Technology, UTU 2013
Information Technology, UTU 203 030000 Fundamentals of Programming Problems to be solved in laboratory Note: Journal should contain followings for all problems given below:. Problem Statement 2. Algorithm
More informationChapter 6. Arrays. Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
1 Chapter 6 Arrays Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Chapter 6 - Arrays 6.1 Introduction 6.2 Arrays 6.3 Declaring Arrays 6.4 Examples Using Arrays
More informationModule 6: Array in C
1 Table of Content 1. Introduction 2. Basics of array 3. Types of Array 4. Declaring Arrays 5. Initializing an array 6. Processing an array 7. Summary Learning objectives 1. To understand the concept of
More informationOutline Introduction Arrays Declaring Arrays Examples Using Arrays Passing Arrays to Functions Sorting Arrays
Arrays Outline 1 Introduction 2 Arrays 3 Declaring Arrays 4 Examples Using Arrays 5 Passing Arrays to Functions 6 Sorting Arrays 7 Case Study: Computing Mean, Median and Mode Using Arrays 8 Searching Arrays
More informationUnit-2 Divide and conquer 2016
2 Divide and conquer Overview, Structure of divide-and-conquer algorithms, binary search, quick sort, Strassen multiplication. 13% 05 Divide-and- conquer The Divide and Conquer Paradigm, is a method of
More informationComputer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];
Arrays An array is a collection of two or more adjacent memory cells, called array elements. Array is derived data type that is used to represent collection of data items. C Array is a collection of data
More informationAn array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type.
Data Structures Introduction An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Representation of a large number of homogeneous
More informationFunctions. Computer System and programming in C Prentice Hall, Inc. All rights reserved.
Functions In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive. You can either use the built-in library functions or you can create
More informationArrays and Applications
Arrays and Applications 60-141: Introduction to Algorithms and Programming II School of Computer Science Term: Summer 2014 Instructor: Dr. Asish Mukhopadhyay What s an array Let a 0, a 1,, a n-1 be a sequence
More informationcalling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!
Chapter 6 - Functions return type void or a valid data type ( int, double, char, etc) name parameter list void or a list of parameters separated by commas body return keyword required if function returns
More informationProgramming in OOP/C++
Introduction Lecture 3-2 Programming in OOP/C++ Arrays Part (2) By Assistant Professor Dr. Ali Kattan 1 Arrays Examples Solutions for previous assignments Write a program to enter and store your name and
More informationC How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.
C How to Program, 6/e 1992-2010 by Pearson Education, Inc. 1992-2010 by Pearson Education, Inc. 1992-2010 by Pearson Education, Inc. This chapter serves as an introduction to the important topic of data
More informationOutline Arrays Examples of array usage Passing arrays to functions 2D arrays Strings Searching arrays Next Time. C Arrays.
CS 2060 Week 5 1 Arrays Arrays Initializing arrays 2 Examples of array usage 3 Passing arrays to functions 4 2D arrays 2D arrays 5 Strings Using character arrays to store and manipulate strings 6 Searching
More informationComputer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons
Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite
More informationCHAPTER 3 ARRAYS. Dr. Shady Yehia Elmashad
CHAPTER 3 ARRAYS Dr. Shady Yehia Elmashad Outline 1. Introduction 2. Arrays 3. Declaring Arrays 4. Examples Using Arrays 5. Multidimensional Arrays 6. Multidimensional Arrays Examples 7. Examples Using
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More informationComputer Programming Lecture 14 Arrays (Part 2)
Computer Programming Lecture 14 Arrays (Part 2) Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical & Electronics Engineering nukhet.ozbek@ege.edu.tr 1 Topics The relationship between
More informationPROGRAMMING IN C AND C++:
PROGRAMMING IN C AND C++: Week 1 1. Introductions 2. Using Dos commands, make a directory: C:\users\YearOfJoining\Sectionx\USERNAME\CS101 3. Getting started with Visual C++. 4. Write a program to print
More informationColumns A[0] A[0][0] = 20 A[0][1] = 30
UNIT Arrays and Strings Part A (mark questions). What is an array? (or) Define array. An array is a collection of same data type elements All elements are stored in continuous locations Array index always
More informationFunction Call Stack and Activation Records
71 Function Call Stack and Activation Records To understand how C performs function calls, we first need to consider a data structure (i.e., collection of related data items) known as a stack. Students
More informationSample Examination. Family Name:... Other Names:... Signature:... Student Number:...
Family Name:... Other Names:... Signature:... Student Number:... THE UNIVERSITY OF NEW SOUTH WALES SCHOOL OF COMPUTER SCIENCE AND ENGINEERING Sample Examination COMP1917 Computing 1 EXAM DURATION: 2 HOURS
More informationC: How to Program. Week /Mar/05
1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers
More informationOne Dimension Arrays 1
One Dimension Arrays 1 Array n Many applications require multiple data items that have common characteristics In mathematics, we often express such groups of data items in indexed form: n x 1, x 2, x 3,,
More informationA First Book of ANSI C Fourth Edition. Chapter 8 Arrays
A First Book of ANSI C Fourth Edition Chapter 8 Arrays Objectives One-Dimensional Arrays Array Initialization Arrays as Function Arguments Case Study: Computing Averages and Standard Deviations Two-Dimensional
More informationChapter 8 Arrays and Strings. Objectives. Objectives (cont d.) Introduction. Arrays 12/23/2016. In this chapter, you will:
Chapter 8 Arrays and Strings Objectives In this chapter, you will: Learn about arrays Declare and manipulate data into arrays Learn about array index out of bounds Learn about the restrictions on array
More informationC Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 2 (Minor modifications by the instructor) 1 Scope Rules A variable declared inside a function is a local variable Each local variable in a function comes into existence when the function
More informationINDIAN SCHOOL MUSCAT COMPUTER SCIENCE(083) CLASS XI
INDIAN SCHOOL MUSCAT COMPUTER SCIENCE(083) CLASS XI 2017-2018 Worksheet No. 1 Topic : Getting Started With C++ 1. Write a program to generate the following output: Year Profit% 2011 18 2012 27 2013 32
More informationQuestions Bank. 14) State any four advantages of using flow-chart
Questions Bank Sub:PIC(22228) Course Code:-EJ-2I ----------------------------------------------------------------------------------------------- Chapter:-1 (Overview of C Programming)(10 Marks) 1) State
More informationArrays. Arrays are of 3 types One dimensional array Two dimensional array Multidimensional array
Arrays Array is a collection of similar data types sharing same name or Array is a collection of related data items. Array is a derived data type. Char, float, int etc are fundamental data types used in
More informationArrays and Strings. Arash Rafiey. September 12, 2017
September 12, 2017 Arrays Array is a collection of variables with the same data type. Arrays Array is a collection of variables with the same data type. Instead of declaring individual variables, such
More informationHow to declare an array in C?
Introduction An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Representation of a large number of homogeneous values.
More informationMaltepe University Computer Engineering Department. BİL 133 Algoritma ve Programlama. Chapter 8: Arrays and pointers
Maltepe University Computer Engineering Department BİL 133 Algoritma ve Programlama Chapter 8: Arrays and pointers Basics int * ptr1, * ptr2; int a[10]; ptr1 = &a[2]; ptr2 = a; // equivalent to ptr2 =
More informationTo become familiar with array manipulation, searching, and sorting.
ELECTRICAL AND COMPUTER ENGINEERING 06-88-211: COMPUTER AIDED ANALYSIS LABORATORY EXPERIMENT #2: INTRODUCTION TO ARRAYS SID: OBJECTIVE: SECTIONS: Total Mark (out of 20): To become familiar with array manipulation,
More informationCS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 06 / 11 / 2015 Instructor: Michael Eckmann Today s Topics Comments and/or Questions? Sorting Searching Michael Eckmann - Skidmore College - CS 106 - Summer 2015
More informationIntroduction to C Final Review Chapters 1-6 & 13
Introduction to C Final Review Chapters 1-6 & 13 Variables (Lecture Notes 2) Identifiers You must always define an identifier for a variable Declare and define variables before they are called in an expression
More informationFunctions. Arash Rafiey. September 26, 2017
September 26, 2017 are the basic building blocks of a C program. are the basic building blocks of a C program. A function can be defined as a set of instructions to perform a specific task. are the basic
More informationC++ Programming. Arrays and Vectors. Chapter 6. Objectives. Chiou. This chapter introduces the important topic of data structures collections
C++ Programming Chapter 6 Arrays and Vectors Yih-Peng Chiou Room 617, BL Building (02) 3366-3603 3603 ypchiou@cc.ee.ntu.edu.tw Photonic Modeling and Design Lab. Graduate Institute of Photonics and Optoelectronics
More informationC: How to Program. Week /Apr/23
C: How to Program Week 9 2007/Apr/23 1 Review of Chapters 1~5 Chapter 1: Basic Concepts on Computer and Programming Chapter 2: printf and scanf (Relational Operators) keywords Chapter 3: if (if else )
More informationC Functions. 5.2 Program Modules in C
1 5 C Functions 5.2 Program Modules in C 2 Functions Modules in C Programs combine user-defined functions with library functions - C standard library has a wide variety of functions Function calls Invoking
More informationUnit 3 Decision making, Looping and Arrays
Unit 3 Decision making, Looping and Arrays Decision Making During programming, we have a number of situations where we may have to change the order of execution of statements based on certain conditions.
More informationChapter 7 Array. Array. C++, How to Program
Chapter 7 Array C++, How to Program Deitel & Deitel Spring 2016 CISC 1600 Yanjun Li 1 Array Arrays are data structures containing related data items of same type. An array is a consecutive group of memory
More informationCSCE 110 PROGRAMMING FUNDAMENTALS. Prof. Amr Goneid AUC Part 7. 1-D & 2-D Arrays
CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 7. 1-D & 2-D Arrays Prof. Amr Goneid, AUC 1 Arrays Prof. Amr Goneid, AUC 2 1-D Arrays Data Structures The Array Data Type How to Declare
More informationChapter 6 Pointers and Arrays
Chapter 6 Pointers and Arrays This chapter addresses the following two issues: 1. How to access a variable (memory location) using its address. 2. How to process a collection of data as a list or a table.
More informationVALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR
VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR 603 203 FIRST SEMESTER B.E / B.Tech., (Common to all Branches) QUESTION BANK - GE 6151 COMPUTER PROGRAMMING UNIT I - INTRODUCTION Generation and
More informationTo declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows
Unti 4: C Arrays Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type An array is used to store a collection of data, but it is often more useful
More informationESC101N: Fundamentals of Computing End-sem st semester
ESC101N: Fundamentals of Computing End-sem 2010-11 1st semester Instructor: Arnab Bhattacharya 8:00-11:00am, 15th November, 2010 Instructions 1. Please write your name, roll number and section below. 2.
More informationDr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)
Lecture 9 Functions Dr M Kasim A Jalil Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Objectives In this chapter, you will learn: To understand how to construct programs modularly
More informationProgramming and Data Structures in C Instruction for students
Programming and Data Structures in C Instruction for students Adam Piotrowski Dariusz Makowski Wojciech Sankowski 11 kwietnia 2016 General rules When writing programs please note that: Program must be
More informationC++ Programming Chapter 7 Pointers
C++ Programming Chapter 7 Pointers Yih-Peng Chiou Room 617, BL Building (02) 3366-3603 ypchiou@cc.ee.ntu.edu.tw Photonic Modeling and Design Lab. Graduate Institute of Photonics and Optoelectronics & Department
More informationObjectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program
Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationUser Manual. Version 3.1. Copyright 2000 Academia Software Solutions All Rights Reserved
The GR System User Manual Version 3.1 Copyright 2000 Academia Software Solutions All Rights Reserved All contents of this manual are copyrighted by Academia Software Solutions. The information contained
More informationChapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationUnit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array?
1 What is an array? Explain with Example. What are the advantages of using an array? An array is a fixed-size sequenced collection of elements of the same data type. An array is derived data type. The
More informationChapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction
Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers
More informationWeek - 03 Lecture - 18 Recursion. For the last lecture of this week, we will look at recursive functions. (Refer Slide Time: 00:05)
Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 03 Lecture - 18 Recursion For the
More informationBLM2031 Structured Programming. Zeyneb KURT
BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help
More informationObjectives. In this chapter, you will:
Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about
More informationC/C++ Programming Lecture 18 Name:
. The following is the textbook's code for a linear search on an unsorted array. //***************************************************************** // The searchlist function performs a linear search
More informationCS 261 Data Structures. Big-Oh Analysis: A Review
CS 261 Data Structures Big-Oh Analysis: A Review Big-Oh: Purpose How can we characterize the runtime or space usage of an algorithm? We want a method that: doesn t depend upon hardware used (e.g., PC,
More informationC: How to Program. Week /Apr/16
C: How to Program Week 8 2006/Apr/16 1 Storage class specifiers 5.11 Storage Classes Storage duration how long an object exists in memory Scope where object can be referenced in program Linkage specifies
More informationDepartment of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #04
Department of Computer Science & Engineering Indian Institute of Technology Kharagpur Topic: Arrays and Strings Practice Sheet #04 Date: 24-01-2017 Instructions: For the questions consisting code segments,
More informationChapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic
More informationProgramming Assignment #4 Arrays and Pointers
CS-2301, System Programming for Non-majors, B-term 2013 Project 4 (30 points) Assigned: Tuesday, November 19, 2013 Due: Tuesday, November 26, Noon Abstract Programming Assignment #4 Arrays and Pointers
More informationCS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych
CS125 : Introduction to Computer Science Lecture Notes #38 and #39 Quicksort c 2005, 2003, 2002, 2000 Jason Zych 1 Lectures 38 and 39 : Quicksort Quicksort is the best sorting algorithm known which is
More informationCS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0)
CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0) Class Teacher: Pralay Mitra Department of Computer Science and Engineering Indian Institute of Technology Kharagpur An Example: Random
More informationUNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING
UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Final Examination December 9, 2011 9:30 a.m. 12:00 p.m. Examiners: J. Anderson, T. Fairgrieve, B. Li, G. Steffan,
More informationBinary Representation. Decimal Representation. Hexadecimal Representation. Binary to Hexadecimal
Decimal Representation Binary Representation Can interpret decimal number 4705 as: 4 10 3 + 7 10 2 + 0 10 1 + 5 10 0 The base or radix is 10 Digits 0 9 Place values: 1000 100 10 1 10 3 10 2 10 1 10 0 Write
More informationDecimal Representation
Decimal Representation Can interpret decimal number 4705 as: 4 10 3 + 7 10 2 + 0 10 1 + 5 10 0 The base or radix is 10 Digits 0 9 Place values: 1000 100 10 1 10 3 10 2 10 1 10 0 Write number as 4705 10
More informationReview of Important Topics in CS1600. Functions Arrays C-strings
Review of Important Topics in CS1600 Functions Arrays C-strings Array Basics Arrays An array is used to process a collection of data of the same type Examples: A list of names A list of temperatures Why
More informationGrade 6 Math Circles November 6 & Relations, Functions, and Morphisms
Faculty of Mathematics Waterloo, Ontario N2L 3G1 Centre for Education in Mathematics and Computing Relations Let s talk about relations! Grade 6 Math Circles November 6 & 7 2018 Relations, Functions, and
More informationFundamentals of Programming Session 15
Fundamentals of Programming Session 15 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines
More informationCS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010
CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011 Lectures 1-22 Moaaz Siddiq Asad Ali Latest Mcqs MIDTERM EXAMINATION Spring 2010 Question No: 1 ( Marks: 1 ) - Please
More informationSorting Pearson Education, Inc. All rights reserved.
1 19 Sorting 2 19.1 Introduction (Cont.) Sorting data Place data in order Typically ascending or descending Based on one or more sort keys Algorithms Insertion sort Selection sort Merge sort More efficient,
More informationCSE101-Lec#18. Multidimensional Arrays Application of arrays. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming
CSE101-Lec#18 Multidimensional Arrays Application of arrays Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Defining and processing 1D array 2D array Applications of arrays 1-D array A
More informationIntroduction to Arrays
Introduction to Arrays One Dimensional Array. Two Dimensional Array. Inserting Elements in Array. Reading Elements from an Array. Searching in Array. Sorting of an Array. Merging of 2 Arrays. What is an
More informationUNIVERSITY OF WINDSOR Fall 2007 QUIZ # 2 Solution. Examiner : Ritu Chaturvedi Dated :November 27th, Student Name: Student Number:
UNIVERSITY OF WINDSOR 60-106-01 Fall 2007 QUIZ # 2 Solution Examiner : Ritu Chaturvedi Dated :November 27th, 2007. Student Name: Student Number: INSTRUCTIONS (Please Read Carefully) No calculators allowed.
More informationCS201 Spring2009 Solved Sunday, 09 May 2010 14:57 MIDTERM EXAMINATION Spring 2009 CS201- Introduction to Programming Question No: 1 ( Marks: 1 ) - Please choose one The function of cin is To display message
More informationSubject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100
Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space
More informationOutline. 7.1 Introduction. 7.2 Arrays. 7.2 Arrays
jhtp5_07.fm Page 279 Wednesday, November 20, 2002 12:44 PM 7 Arrays Objectives To introduce the array data structure. To understand the use of arrays to store, sort and search lists and tables of values.
More informationONE DIMENSIONAL ARRAYS
LECTURE 14 ONE DIMENSIONAL ARRAYS Array : An array is a fixed sized sequenced collection of related data items of same data type. In its simplest form an array can be used to represent a list of numbers
More information