1 juil 2020 · Array Example Exercise References Arrays-I Arrays (1D and 2D) 9 10 // Declaration and Initialization 11 int x[10] = {1 ,2 ,3 ,4 ,5}; 12
View & Download This PDF
Dr Papalaskari 2D Array Exercise Objectives: Practice using two dimensional arrays to input and output data in a tabular format A Simple 2D array example
Exercises: Arrays int[] intArr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; for (int i Declare and instantiate on a single line a two-dimensional array called intArr that holds int
Given a 2-d array m, re-order the rows such that the row with the highest row 9 4 5 8 3 5 4 9 8 3 Hint: Once you find the largest-sum column, you will need to
Two dimensional array c exercises pdf Continue array= numberarray= 0= 1= 2 = using= 2-d= arrays:= #include=> // ڈ ی 2 اﯾ ﮏ ﻧ ﻢ
1 juil 2020 · Array Example Exercise References Arrays-I Arrays (1D and 2D) 9 10 // Declaration and Initialization 11 int x[10] = {1 ,2 ,3 ,4 ,5}; 12
2 Characters, strings and 2D array 3 Manipulating 2D array elements 4 Tutorial references that should be used together with this worksheet are C C++ array
spreadsheet, which need a two-dimensional array • Examples: 0 1 2 3 0 4 6 2 5 1 7 9 4 8 2 6 9 3 7 movie (second index) (first index) reviewer rating 3
C# allows programmers to create and use multi-dimensional arrays, For example, to access an element located at row R and column C, we can use: Exercise 1 1: Typethe following program in SharpDevelop then answer the ques- tions
[PDF] two dimensional array in java example program
[PDF] two dimensional array java
[PDF] two dimensional array java exercises
[PDF] two dimensional discrete fourier transform in digital image processing
[PDF] two dimensional fourier series
[PDF] two dimensional fourier transform python
[PDF] two sample anderson darling test r
[PDF] two style types in word and their use
[PDF] two tier architecture advantages and disadvantages
[PDF] two tier server
[PDF] two types of asexual reproduction
[PDF] two types of certificate of deposit
[PDF] two way radio communication training
[PDF] two way radio frequency list philippines
[PDF] two wheeler automobile engineering pdf
U3 Arrays (1D and 2D)
Mr. J. Mishra MGCUB, INDIA Objectives Introduction Declaration and Initialization Manipulation Operations on Arrays Array Example Exercise References Arrays-I Arrays (1D and 2D) Course: BTech in CSE Course Name: Programming for Problem Solving Course Code: Semester: II Session: 2019-20 Mr. Joynath Mishra Assistant Professor (Guest) Department of Computer Science and Information Technology
Mahatma Gandhi Central University Bihar, INDIA May 31, 2020 U3 Arrays (1D and 2D)
Mr. J. Mishra MGCUB, INDIA Objectives Introduction Declaration and Initialization Manipulation Operations on Arrays Array Example Exercise References Outline 1Objectives 2Introduction 3Declaration and Initialization 4Manipulation 5Operations on Arrays 6Array Example 7Exercise 8References U3 Arrays (1D and 2D)
Mr. J. Mishra MGCUB, INDIA Objectives Introduction Declaration and Initialization Manipulation Operations on Arrays Array Example Exercise References Objectives Objectives Concept of array Study on declaration and initialization of array Operations on array Study on 1D and 2D array U3 Arrays (1D and 2D)
Mr. J. Mishra MGCUB, INDIA Objectives Introduction Declaration and Initialization Manipulation Operations on Arrays Array Example Exercise References Introduction[1],[2],[3] Introduction Collection of similar type of primitive data type Addressed by a common variable name Homogeneous continous memory location Array data types: char, int, float, double Randomly accessed elements by indices (subscript value starts from 0)
Figure 1 U3 Arrays (1D and 2D)
Mr. J. Mishra MGCUB, INDIA Objectives Introduction Declaration and Initialization Manipulation Operations on Arrays Array Example Exercise References Declaration and Initialization One Dimensional Array Declaration and Initialization 1//Array declaration 2charch [ 1 0 ] ; 3intx [ 1 0 ] ; 4floatf [ 1 0 ] ; 5// I n i t i a l i z a t i o n 6x [10] ={1 ,2 ,3 ,4 ,5}; 7ch [10] ={"M","G","C ","U"}; 8f [10] ={3.2 , 5.3 , 1.2}; 9
10// Declaration and I n i t i a l i z a t i o n 11intx [10] ={1 ,2 ,3 ,4 ,5}; 12charch [10] ={"M","G","C ","U"}; 13floatf [10] ={3.2 , 5.3 , 1.2}; 14
15//Dynamic I n i t i a l i z a t i o n ( without size ) 16intx [ ] ={1 ,2 ,3 ,4 ,5}; 17charch [ ] ={"M","G","C ","U"}; 18floatf [ ] ={3.2 , 5.3 , 1.2}; Graphical Representation Figure 2 Figure 3 U3 Arrays (1D and 2D)
Mr. J. Mishra MGCUB, INDIA Objectives Introduction Declaration and Initialization Manipulation Operations on Arrays Array Example Exercise References Declaration and Initialization (Contd...) Two Dimensional Array Two Dimensional Array Two dimensional array is stored in row-column format First indices indicate row and second indices indicate column
Similarly, multi-dimensional arrays are possible Declaration and Initialization 1// Declaration and I n i t i a l i z a t i o n 2intx [ 2 ] [ 3 ] ={{1, 3 , 0},{-1, 5 , 9}}; 3intx [ ] [ 3 ] ={{1, 3 , 0},{-1, 5 , 9}}; 4intx [ 2 ] [ 3 ] ={1, 3 , 0 ,-1, 5 , 9}; 5 6
7// I n i t i a l i z a t i o n with missing values 8inty [ 5 ] [ 3 ] ={1, 2 , 3 , 4 , 5 , 6 , 7}; Figure 5 Graphical Representation Figure 6 Figure 7 U3 Arrays (1D and 2D)
Mr. J. Mishra MGCUB, INDIA Objectives Introduction Declaration and Initialization Manipulation Operations on Arrays Array Example Exercise References Manipulation One and Two Dimensional Array Array Element Manipulation 1#include 2intmain () 3{
4intx [10] ={1, 2 , 3 , 4 , 5}; 5
6p r i n t f ("Entered array i s : ") ; 7for(inti =0; x [ i ]!=0; i++) 8p r i n t f ("\t%d", x [ i ]) ; 9 10
11// Print stored value at x [2] 12p r i n t f ("\nThird value of x :\t%d", x [2]) ; 13 14
15//Sum of two elements 16intsum = x [1] + x [ 3 ] ; 17p r i n t f ("\nSum of two elements :\t%d", sum) ; 18 19
20// Storing value in array 21x [3] = 24; 22p r i n t f ("\nNew value of x [3]:\t%d", x [3]) ; 23
24p r i n t f ("\n") ; 25p r i n t f ("\nAddress of array :\t%p", &x) ; 26p r i n t f ("\nStarting address of array :\t%p", &x [0]) ; 27p r i n t f ("\nLast address of array :\t%p", &x [9]) ; 28
29return0; 30}
Output Entered array is: 1 2 3 4 5 Third value of x : 3 Sum of two elements: 6 New value of x[3]: 24 Address of array: 0x7ffc6e16ded0 Starting address of array: 0x7ffc6e16ded0 Last address of array: 0x7ffc6e16def4 U3 Arrays (1D and 2D)
Mr. J. Mishra MGCUB, INDIA Objectives Introduction Declaration and Initialization Manipulation Operations on Arrays Array Example Exercise References Operations on Arrays Traversal Processing each element in the array or list Search Find a location and value with given key in array Algorithms: linear search, binary search Insertion Adding a new value to array at start, middle, end location
Deletion Removing a value from array at start, middle, end loaction
Sorting Arranging elements in ascending or descending order
Algorithms: Insertion, Bubble, Quick sort Merging Compibing two list or arrays U3 Arrays (1D and 2D)
Mr. J. Mishra MGCUB, INDIA Objectives Introduction Declaration and Initialization Manipulation Operations on Arrays Array Example Exercise References Array Example Example 1 Average Temperature (1D Array) 1/?Average temperature of a week?/ 2#include 3intmain () 4{
5inti ; 6floataverage , temp [7] , total ; 7p r i n t f (" Please enter seven days temperature :\t") ; 8
9for( i =0;i<7;i++) 10scanf ("%f ", &temp [ i ]) ; 11
12for( i =0;i<7;i++) 13total = total + temp [ i ] ; 14
15average = total /7; 16
17p r i n t f ("Seven days average temperature : %f ", average ) ; 18return0; 19}
Output Please enter seven days temperature: 12 12 13 22 12 13 14
Seven days average temperature: 14.000000 U3 Arrays (1D and 2D)
Mr. J. Mishra MGCUB, INDIA Objectives Introduction Declaration and Initialization Manipulation Operations on Arrays Array Example Exercise References Array Example Example 2 Searching largest and smallest value (1D Array) 1/?Find largest and smallest value?/ 2#include 3#defineMAX 20 4intmain () 5{
6inta [MAX] , i , n , large , small ; 7p r i n t f ("How many elements : ") ; 8scanf ("%d",&n) ; 9p r i n t f ("Enter the Array : ") ; 10
11for( i =0;i 12scanf ("%d",&a [ i ]) ; 13 14large=small=a [ 0 ] ; 15for( i =1;i 16{ 17i f(a [ i]>large ) 18large=a [ i ] ; 19i f(a [ i] 20small=a [ i ] ; 21} 22 23p r i n t f ("The largest element i s %d", large ) ; 24p r i n t f ("\nThe smallest element i s %d", small ) ; 25 26return0; 27} Output How many elements:5 Enter the Array:3 7 1 9 3 The largest element is 9 The smallest element is 1 U3 Arrays (1D and 2D) Mr. J. Mishra MGCUB, INDIA Objectives Introduction Declaration and Initialization Manipulation Operations on Arrays Array Example Exercise References Array Example Example 3 Matrix Addition (2D Array) 1#include/?Matrix Addition?/ 2intmain () 3{ 4intr , c , a [50][50] , b [50][50] , sum [50][50] , i , j ; 5p r i n t f ("Enter number of rows and column :\t") ; 6scanf ("%d%d", &r , &c) ; 7p r i n t f ("Enter elements of 1 st matrix :\n") ; 8for( i = 0; i 9for( j = 0; j 10scanf ("%d", &a [ i ] [ j ]) ; 11 12p r i n t f ("Enter elements of 2nd matrix :\n") ; 13for( i = 0; i 14for( j = 0; j 15scanf ("%d", &b [ i ] [ j ]) ; 16 17for( i = 0; i 18for( j = 0; j 19sum[ i ] [ j ] = a [ i ] [ j ] + b [ i ] [ j ] ; 20 21p r i n t f ("\nSum of two matrices :\n") ; 22for( i = 0; i 23{ 24for( j = 0; j 25p r i n t f ("%d ", sum[ i ] [ j ]) ; 26p r i n t f ("\n\n") ; 27} 28return0; 29} Output Enter number of rows and column: 3 3 Enter elements of 1st matrix: 1 2 3 4 5 6 7 8 9 Enter elements of 2nd matrix: 9 8 7 6 5 4 3 2 1 Sum of two matrices: 10 10 10 10 10 10 10 10 10 U3 Arrays (1D and 2D) Mr. J. Mishra MGCUB, INDIA Objectives quotesdbs_dbs14.pdfusesText_20