SlideShare a Scribd company logo
Declaration, Initialisation , Reading & Writing
of Arrays
• We have used the fundamental data types, char,
int, float, double.
• These types are constrained by the fact that a
variable of these types can store only one value at
any given time
• In many applications, we need to handle large
volumes of data
• To process such large amounts of data, we need a
powerful data types that would facilitate efficient
storing, accessing and manipulation of data items
• C supports a derived data type known as array.
• An array is a fixed-sized sequenced collection of
elements of the same data type thats shares a
common name.
• The common name a is the array name and each
individual data item is known as an element of the
array.
• The elements of the array are stored in the
subsequent memory locations starting from the
memory location given by the array name.
 Array can be classified as two types are,
1. One-Dimensional Array
2. Two-Dimensional or multidimensional
Array
 One-Dimensional Array
◦ A one-dimensional array can be used to represent a
list of data items. It is also known as a vector.
 Two-Dimensional Array
◦ A two dimensional array can be used to represent a
table of data items consisting of rows and columns.
It is also known as a matrix
 Every array must be declared before use like other
variables.
 The declarations of one-dimensional and
multidimensional arrays differ slightly.
 Declaration of One-dimensional array:
where
data_type refers to the data type of elements in the array.
It can be a primitive or derived data type.
name is an identifier which represents the array name.
size is an integer expression representing the total
number of elements in the array.
data_type name1[size1], name2[size2],…, namen[sizen];
 The base address of an array is the address of the
zeroth element (starting element) of that array.
 When an array is declared, the compiler allocates a base
address and reserves enough space in memory for all
the elements of the array.
 In C, the array name represents this base address.
 For example, float x[5]; is the declaration of a one-
dimensional array.
 It defines a float array x of size 5 that represents a
block of 5 consecutive storage regions.
 Each element in the array is referred to by the array
variables x[0], x[1], x[2] ,x[3] and x[4] where 0,1,2,3
and 4 represent subscripts or indices of the array.
 In general, x[i] refers to the ith element of the array.
 The array subscripts always start at zero in C and
they are integer expressions.
 Hence, x[0] refers to the starting element, x[1] refers
to the next element and x[4] refers to the last
element.
 The declaration double list[10], array[15]; declares
two arrays, named list and array having 10 and 15
elements respectively of double precision data type.
 The elements of an array may be assigned with the values using
initialisation instead of reading them by the I/O functions.
 An array can be initialised in its declaration only.
 The list of initialisers (values) are enclosed in braces.
 The initialisers are separated by commas and they must be
constants or constant expressions.
 One-dimensional array can be initialised as given below.
int a[4]={3,5, -8, 10};
 The values within the braces are scanned from left end and
assigned to a[0], a[1] and so on.
 A semicolon should be placed after the closing brace.
“For “ loops used extensively for array processing
Example 1: write a program to read an array and
print.
#include<stdio.h>
void main()
{
int i,a[10];
for(i=0;i<10;i++)
scanf(“%d”,&a[i]);
for(i=0;i<10;i++)
Printf(“n %d”,a[i]);
}
#include<stdio.h>
void main()
{
int x[2],i;
printf("nEnter the inputs:");
for(i=0;i<2;i++)
scanf("%d",&x[i]);
for(i=0;i<2;i++)
printf("nThe value in x[%d] is %d",i,x[i]);
}
OUTPUT:
Enter the inputs:3
6
The value in x[0] is 3
The value in x[1] is 6
/*Determines the length of a message */
#include<stdio.h>
main()
{
char ch;
int len=0;
printf(“Enter a message : ”);
ch=getchar();
while (ch!=‘n’) {
len++;
ch=getchar();
}
printf(“Your message was %d character(s) long. n”,
len);
return 0;
}
 The c languages treats strings as arrays of characters
 The compiler terminates the character strings with an
additional null (‘0’) character.
 String is a one dimensional array of characters in c.
 The element name[10] holds the null character ‘0’ at
the end
 When declaring character arrays, we must always allow
one extra elements space for the null terminator
#include<stdio.h>
void main()
{
int i=0;
char a[]="abcd";
while(a[i]!='0')
{
printf("t%c",a[i]);
i++;
}
}
OUTPUT:
a b c d
 There are different way to initialize a character array variable.
char name[10]=“StudingTonight”; //valid initialization
char name[10]={‘L’,’E’,’S’,’S’,’O’,’N’,’S’,’0’}; // valid Init
Some example for illegal Initialization of character array are,
char ch[3]=“hello”; // Illegal
char str[4];
str=“hello”; //illegal
Format:
data_type array_name[row_size1][column_size1];
 The first subscript represents the row size and the second subscript
represents the column size.
 The value in the ith row and jth column is referred to by name[i][j].
 The total number of elements in a two dimensional array is calculated
by multiplying the number of rows by the number of columns.
 In two-dimensional arrays, the values are stored row by row.
 int x[3][2];
 For example, the declaration int a[3][2] ,b[7][4]; defines
the two-dimensional integer arrays a and b.
 These arrays are arrays of integer arrays.
 Six (rows * columns) elements of a are stored row by row
in the consecutive memory locations.
 This method of storing the elements in the memory is
known as row major order storage representation
 The zeroth element of array a is denoted by a[0][0] and the
last element in that array is denoted by a[2][1].
 Similarly, for the array b, the zeroth element and the last
element are represented by b[0][0] and b[6][3] respectively.
Starting element a[0][0]
a[0][1]
a[1][0]
a[1][1]
a[2][0]
Last element a[2][1]
Row 0
Row 1Row 1
Row 2
Storage representation of matrix a
Syntax:
data_type array_name[row_size][col_size]={variables};
 A two-dimensional array can be initialised as given below.
int a[3][2] = {20, 25, -3, 8, -5, 7};
 Here, the initialised values are assigned to the array elements
according to the order of the storage in the memory.
 But if the initialisers are enclosed within the inner braces as given
below
int a[3][2] = {{20,25}, {-3, 8}, {-5,7}};
 The initialised values within the inner braces are assigned to each row.
 To enforce the assignment of each row, it is essential to use the inner
braces.
 If the number of values initialised for an array is less than the size
mentioned, the missing elements are assigned zero. In the initialisation
int a[3][4] = { {1,2},{4,8,15} };
 the elements a[0][0] and a[0][1] of the zeroth row and a[1][0], a[1][1] and
a[1][2] of the first row are initialised with the values 1,2,4,8 and 15
respectively.
 All the other elements are initialised to zero.
 If it is given as
int a[3][4] = {1,2,3,8,15};
 the values are assigned from the left end to a[0][0], a[0][1], a[0][2],
a[0][3], and a[[1][0] according to the order of the storage representation.
 If the number of initialisers exceeds the size of the array, it is an error.
 The size of a one-dimensional array need not be mentioned in its
initialisation.
 In this case, the compiler will count the values assigned and take it
as the size of that array.
 In multidimensional arrays the leftmost subscript may be omitted
and all the others must be specified. The initialisation
int x[ ] = {2,4,6,8,10};
 makes the array x having 5 elements
float a[ ][2] = {{3.2,4.8}, {5.3,3.7}};
 makes the array a having 2 rows and 2 columns.
#include<stdio.h>
void main()
{
int i,j;
int x[2][2]={ {1,50},
{2,75}
};
for(i=0;i<2;i++)
for(j=0;j<2;j++)
printf("nThe value in x[%d][%d] is %d",i,j,x[i][j]);
}
OUTPUT:
The value in x[0][0] is 1
The value in x[0][1] is 50
The value in x[1][0] is 2
The value in x[1][1] is 75
#include<stdio.h>
void main()
{
int i,j;
int x[][2]={ {1,50},{2,75},{3,65}};
for(i=0;i<=2;i++)
for(j=0;j<2;j++)
printf("nThe value in x[%d][%d] is %d",i,j,x[i][j]);
}
OUTPUT:
The value in x[0][0] is 1
The value in x[0][1] is 50
The value in x[1][0] is 2
The value in x[1][1] is 75
The value in x[2][0] is 3
The value in x[2][1] is 65
/* PROGRAM TO FIND THE MINIMUM VALUE AND ITS POSITION */
#include<stdio.h>
#define MAX 5
main( )
{
int a[MAX],i,min;
int pos = 0; /* Fixing position if the first number is
the minimum value */
printf("Enter the array elementsn");
for(i=0;i<MAX;i++)
scanf("%d",&a[i]);
min=a[0];
for(i=1;i<MAX;i++)
if(a[i] < min)
{
min=a[i];
pos=i; /* Fixing the minimum value position*/
}
printf(“ MINIMUM VALUE = %dn”,min);
printf(“ POSITION = %dn”,pos);
}
SAMPLE INPUT AND OUTPUT
Enter the array elements
14 29 37 25 45
MINIMUM VALUE = 14
POSITION = 0
#define MAXROW 2
#define MAXCOL 4
main( )
{
int s[MAXROW][MAXCOL],t[MAXCOL][MAXROW];
int i,j;
printf("Enter the values of the matrixn");
for(i=0;i<MAXROW;i++)
for(j=0;j<MAXCOL;j++)
scanf("%d",&s[i][j]);
printf("nGiven Matrixnn");
for(i=0;i<MAXROW;i++)
{
for(j=0;j<MAXCOL;j++)
printf("%dt",s[i][j]);
printf("n");
}
for(i=0;i<MAXCOL;i++)
for(j=0;j<MAXROW;j++)
t[i][j] = s[j][i];
printf("nTranspose of the matrixnn");
for(i=0;i<MAXCOL;i++)
{
for(j=0;j<MAXROW;j++)
printf("%dt",t[i][j]); printf("n");
}
}
SAMPLE INPUT AND OUTPUT
Enter the values of the matrix
10 20 30 40 50 60 70 80
Given Matrix
10 20 30 40
50 60 70 80
Transpose of the matrix
10 50
20 60
30 70
40 80
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,r1,r2,c1,c2;
int a[5][5],b[5][5],c[5][5];
clrscr();
//step1:
printf("n Enter the size of matrix
A:");
scanf("%d%d",&r1,&c1);
printf("n Enter the size of matrix
B: ");
scanf("%d%d",&r2,&c2);
if((c1==c2)&&(r1==r2))
goto step2;
else
goto step1;
//step2:
printf("n Enter the elements of matrix
A n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("n Enter the elements of matrix
B n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("t%d",&b[i][j]);
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
c[i][j]=0;
c[i][j]=c[i][j]+a[i][j]+b[i][j];
}
}
printf("n The resultant matrix
after addition of A & B isn");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%dt",c[i][j]);
printf("n");
}
getch();
}
OUTPUT:
Enter the size of matrix A: 2
2
Enter the size of matrix B: 2
2
Enter the elements of matrix A
2
2
2
2
Enter the elements of matrix B
3
3
3
3
The resultant matrix after addition
of A&B is
5 5
5 5
/* PROGRAM TO REMOVE THE DUPLICATE ELEMENTS IN AN ARRAY */
#define MAX 5
main( )
{
int a[MAX];
int i,j,k,n=MAX,p;
for(i=0;i<n;i++)
{
printf("Enter the value of a[%d]:n",i);
scanf("%d",&a[i]);
}
printf("Array before deleting duplicate elementsn");
for(i=0;i<n;i++)
printf("%dt",a[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)

{
if(a[i] == a[j])
{
p = i ;
for(k=j;k<n;k++)
a[k] =a[++j];
j = p; n--;
}
}
}
putchar('n');
printf("Array after deleting duplicate elementsn");
for(i=0;i<n;i++)
printf("%dt",a[i]);
putchar('n');
}
SAMPLE INPUT AND OUTPUT
Enter the value of a[0]:
5
Enter the value of a[1]:
8
Enter the value of a[2]:
5
Enter the value of a[3]:
12
Enter the value of a[4]:
8
Array before deleting duplicate elements
5 8 5 12
8
Array after deleting duplicate elements
5 8 12
/* PROGRAM TO SORT AN ARRAY */
#define MAX 5
main( )
{
int a[MAX],i,j,temp;
printf("Enter the array elementsn");
for(i=0;i<MAX;i++)
scanf("%d",&a[i]);
for(i=0;i<MAX;i++)
for(j=i+1;j<MAX;j++)
{
if(a[i] >a[j])
Example Programs
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
printf("nAscending ordern");
for(i=0;i<MAX;i++)
printf("%dt",a[i]);
printf("nDescending ordern");
for(i=MAX-1;i>=0;i--)
printf("%dt",a[i]);
}
SAMPLE INPUT AND OUTPUT
Enter the array elements
11 15 20 45 15
Ascending order
11 15 15 20 45
Descending order
45 20 15 15 11
Example Programs
/*PROGRAM TO CONVERT A 2-D ARRAY TO 1-D ARRAY */
#define MAXROW 3
#define MAXCOL 2
main( )
{
int a[MAXROW][MAXCOL],b[MAXROW*MAXCOL];
int i,j,k=0;
printf("Enter the matrix elements in row ordern");
for(i=0;i<MAXROW;i++)
for(j=0;j<MAXCOL;j++)
{
scanf("%d",&a[i][j]);
Example Programs
b[k++] = a[i][j];
}
printf("Given two-dimensional arrayn");
for(i=0;i<MAXROW;i++)
{
for(j=0;j<MAXCOL;j++)
printf("%dt",a[i][j]);
printf("n");
}
printf("Equivalent one-dimensional arrayn");
for(i=0;i<MAXROW*MAXCOL;i++)
printf("%dt",b[i]);
}
SAMPLE INPUT AND OUTPUT
Enter the matrix elements in row order
10 15 20 25 30 35
Given two-dimensional array
10 15
20 25
30 35
Equivalent one-dimensional array
10 15 20 25 30 35
Example Programs
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional

More Related Content

What's hot

Array in c programming
Array in c programmingArray in c programming
Array in c programming
Mazharul Islam
 
Array ppt
Array pptArray ppt
Array ppt
Kaushal Mehta
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
Arrays in c
Arrays in cArrays in c
Arrays in c
Jeeva Nanthini
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
sandhya yadav
 
Array operations
Array operationsArray operations
Array operations
ZAFAR444
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
Neeru Mittal
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
KristinaBorooah
 
Array in c++
Array in c++Array in c++
Array in c++
Mahesha Mano
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
Dr.Subha Krishna
 
Array in c
Array in cArray in c
Array in c
Ravi Gelani
 
Structure in C
Structure in CStructure in C
Structure in C
Kamal Acharya
 
2D Array
2D Array 2D Array
2D Array
Ehatsham Riaz
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
CGC Technical campus,Mohali
 
Linked list
Linked listLinked list
Linked list
akshat360
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
shameen khan
 
Arrays in c
Arrays in cArrays in c
Arrays in c
CHANDAN KUMAR
 

What's hot (20)

Array in c programming
Array in c programmingArray in c programming
Array in c programming
 
Array ppt
Array pptArray ppt
Array ppt
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Array operations
Array operationsArray operations
Array operations
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Array in c++
Array in c++Array in c++
Array in c++
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Array in c
Array in cArray in c
Array in c
 
Structure in C
Structure in CStructure in C
Structure in C
 
2D Array
2D Array 2D Array
2D Array
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
 
Linked list
Linked listLinked list
Linked list
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Strings
StringsStrings
Strings
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 

Viewers also liked

Storage classess of C progamming
Storage classess of C progamming Storage classess of C progamming
Storage classess of C progamming
Appili Vamsi Krishna
 
C language for Semester Exams for Engineers
C language for Semester Exams for Engineers C language for Semester Exams for Engineers
C language for Semester Exams for Engineers
Appili Vamsi Krishna
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
Appili Vamsi Krishna
 
BE Aerospace Syllabus of MIT, Anna University R2015
BE Aerospace Syllabus of MIT, Anna University R2015BE Aerospace Syllabus of MIT, Anna University R2015
BE Aerospace Syllabus of MIT, Anna University R2015
Appili Vamsi Krishna
 
Difference between structure and union
Difference between structure and unionDifference between structure and union
Difference between structure and union
Appili Vamsi Krishna
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
Appili Vamsi Krishna
 
Types of storage class specifiers in c programming
Types of storage class specifiers in c programmingTypes of storage class specifiers in c programming
Types of storage class specifiers in c programming
Appili Vamsi Krishna
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
Appili Vamsi Krishna
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
Appili Vamsi Krishna
 
Planers machine
Planers machinePlaners machine
Planers machine
Bilalwahla
 
Conventional machining vs. non conventional machining
Conventional machining vs. non conventional machiningConventional machining vs. non conventional machining
Conventional machining vs. non conventional machining
onlinemetallurgy.com
 

Viewers also liked (12)

Storage classess of C progamming
Storage classess of C progamming Storage classess of C progamming
Storage classess of C progamming
 
C language for Semester Exams for Engineers
C language for Semester Exams for Engineers C language for Semester Exams for Engineers
C language for Semester Exams for Engineers
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
BE Aerospace Syllabus of MIT, Anna University R2015
BE Aerospace Syllabus of MIT, Anna University R2015BE Aerospace Syllabus of MIT, Anna University R2015
BE Aerospace Syllabus of MIT, Anna University R2015
 
Difference between structure and union
Difference between structure and unionDifference between structure and union
Difference between structure and union
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
Types of storage class specifiers in c programming
Types of storage class specifiers in c programmingTypes of storage class specifiers in c programming
Types of storage class specifiers in c programming
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
 
Planers machine
Planers machinePlaners machine
Planers machine
 
Conventional machining vs. non conventional machining
Conventional machining vs. non conventional machiningConventional machining vs. non conventional machining
Conventional machining vs. non conventional machining
 

Similar to Arrays 1D and 2D , and multi dimensional

Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
Thesis Scientist Private Limited
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Boro
 
ARRAYS
ARRAYSARRAYS
ARRAYS
muniryaseen
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
Rakesh Roshan
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
Arrays
ArraysArrays
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
Md. Imran Hossain Showrov
 
Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
chanchal ghosh
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
HEMAHEMS5
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
nmahi96
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
Ashim Lamichhane
 
About Array
About ArrayAbout Array
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
Munazza-Mah-Jabeen
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
eShikshak
 
Arrays
ArraysArrays
02 arrays
02 arrays02 arrays
02 arrays
Rajan Gautam
 
Array
ArrayArray

Similar to Arrays 1D and 2D , and multi dimensional (20)

Session 7 En
Session 7 EnSession 7 En
Session 7 En
 
Session 7 En
Session 7 EnSession 7 En
Session 7 En
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
ARRAYS
ARRAYSARRAYS
ARRAYS
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
 
Arrays
ArraysArrays
Arrays
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
 
Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
About Array
About ArrayAbout Array
About Array
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
 
Arrays
ArraysArrays
Arrays
 
02 arrays
02 arrays02 arrays
02 arrays
 
Array
ArrayArray
Array
 
Array
ArrayArray
Array
 

Recently uploaded

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 

Recently uploaded (20)

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 

Arrays 1D and 2D , and multi dimensional

  • 1. Declaration, Initialisation , Reading & Writing of Arrays
  • 2. • We have used the fundamental data types, char, int, float, double. • These types are constrained by the fact that a variable of these types can store only one value at any given time • In many applications, we need to handle large volumes of data • To process such large amounts of data, we need a powerful data types that would facilitate efficient storing, accessing and manipulation of data items
  • 3. • C supports a derived data type known as array. • An array is a fixed-sized sequenced collection of elements of the same data type thats shares a common name. • The common name a is the array name and each individual data item is known as an element of the array. • The elements of the array are stored in the subsequent memory locations starting from the memory location given by the array name.
  • 4.  Array can be classified as two types are, 1. One-Dimensional Array 2. Two-Dimensional or multidimensional Array
  • 5.  One-Dimensional Array ◦ A one-dimensional array can be used to represent a list of data items. It is also known as a vector.  Two-Dimensional Array ◦ A two dimensional array can be used to represent a table of data items consisting of rows and columns. It is also known as a matrix
  • 6.  Every array must be declared before use like other variables.  The declarations of one-dimensional and multidimensional arrays differ slightly.  Declaration of One-dimensional array: where data_type refers to the data type of elements in the array. It can be a primitive or derived data type. name is an identifier which represents the array name. size is an integer expression representing the total number of elements in the array. data_type name1[size1], name2[size2],…, namen[sizen];
  • 7.  The base address of an array is the address of the zeroth element (starting element) of that array.  When an array is declared, the compiler allocates a base address and reserves enough space in memory for all the elements of the array.  In C, the array name represents this base address.  For example, float x[5]; is the declaration of a one- dimensional array.  It defines a float array x of size 5 that represents a block of 5 consecutive storage regions.
  • 8.  Each element in the array is referred to by the array variables x[0], x[1], x[2] ,x[3] and x[4] where 0,1,2,3 and 4 represent subscripts or indices of the array.  In general, x[i] refers to the ith element of the array.  The array subscripts always start at zero in C and they are integer expressions.  Hence, x[0] refers to the starting element, x[1] refers to the next element and x[4] refers to the last element.  The declaration double list[10], array[15]; declares two arrays, named list and array having 10 and 15 elements respectively of double precision data type.
  • 9.  The elements of an array may be assigned with the values using initialisation instead of reading them by the I/O functions.  An array can be initialised in its declaration only.  The list of initialisers (values) are enclosed in braces.  The initialisers are separated by commas and they must be constants or constant expressions.  One-dimensional array can be initialised as given below. int a[4]={3,5, -8, 10};  The values within the braces are scanned from left end and assigned to a[0], a[1] and so on.  A semicolon should be placed after the closing brace.
  • 10. “For “ loops used extensively for array processing Example 1: write a program to read an array and print. #include<stdio.h> void main() { int i,a[10]; for(i=0;i<10;i++) scanf(“%d”,&a[i]); for(i=0;i<10;i++) Printf(“n %d”,a[i]); }
  • 11.
  • 12. #include<stdio.h> void main() { int x[2],i; printf("nEnter the inputs:"); for(i=0;i<2;i++) scanf("%d",&x[i]); for(i=0;i<2;i++) printf("nThe value in x[%d] is %d",i,x[i]); } OUTPUT: Enter the inputs:3 6 The value in x[0] is 3 The value in x[1] is 6
  • 13. /*Determines the length of a message */ #include<stdio.h> main() { char ch; int len=0; printf(“Enter a message : ”); ch=getchar(); while (ch!=‘n’) { len++; ch=getchar(); } printf(“Your message was %d character(s) long. n”, len); return 0; }
  • 14.  The c languages treats strings as arrays of characters  The compiler terminates the character strings with an additional null (‘0’) character.  String is a one dimensional array of characters in c.  The element name[10] holds the null character ‘0’ at the end  When declaring character arrays, we must always allow one extra elements space for the null terminator
  • 15. #include<stdio.h> void main() { int i=0; char a[]="abcd"; while(a[i]!='0') { printf("t%c",a[i]); i++; } } OUTPUT: a b c d
  • 16.  There are different way to initialize a character array variable. char name[10]=“StudingTonight”; //valid initialization char name[10]={‘L’,’E’,’S’,’S’,’O’,’N’,’S’,’0’}; // valid Init Some example for illegal Initialization of character array are, char ch[3]=“hello”; // Illegal char str[4]; str=“hello”; //illegal
  • 17. Format: data_type array_name[row_size1][column_size1];  The first subscript represents the row size and the second subscript represents the column size.  The value in the ith row and jth column is referred to by name[i][j].  The total number of elements in a two dimensional array is calculated by multiplying the number of rows by the number of columns.  In two-dimensional arrays, the values are stored row by row.
  • 19.  For example, the declaration int a[3][2] ,b[7][4]; defines the two-dimensional integer arrays a and b.  These arrays are arrays of integer arrays.  Six (rows * columns) elements of a are stored row by row in the consecutive memory locations.  This method of storing the elements in the memory is known as row major order storage representation  The zeroth element of array a is denoted by a[0][0] and the last element in that array is denoted by a[2][1].  Similarly, for the array b, the zeroth element and the last element are represented by b[0][0] and b[6][3] respectively.
  • 20. Starting element a[0][0] a[0][1] a[1][0] a[1][1] a[2][0] Last element a[2][1] Row 0 Row 1Row 1 Row 2 Storage representation of matrix a
  • 21. Syntax: data_type array_name[row_size][col_size]={variables};  A two-dimensional array can be initialised as given below. int a[3][2] = {20, 25, -3, 8, -5, 7};  Here, the initialised values are assigned to the array elements according to the order of the storage in the memory.  But if the initialisers are enclosed within the inner braces as given below int a[3][2] = {{20,25}, {-3, 8}, {-5,7}};  The initialised values within the inner braces are assigned to each row.  To enforce the assignment of each row, it is essential to use the inner braces.
  • 22.  If the number of values initialised for an array is less than the size mentioned, the missing elements are assigned zero. In the initialisation int a[3][4] = { {1,2},{4,8,15} };  the elements a[0][0] and a[0][1] of the zeroth row and a[1][0], a[1][1] and a[1][2] of the first row are initialised with the values 1,2,4,8 and 15 respectively.  All the other elements are initialised to zero.  If it is given as int a[3][4] = {1,2,3,8,15};  the values are assigned from the left end to a[0][0], a[0][1], a[0][2], a[0][3], and a[[1][0] according to the order of the storage representation.  If the number of initialisers exceeds the size of the array, it is an error.
  • 23.  The size of a one-dimensional array need not be mentioned in its initialisation.  In this case, the compiler will count the values assigned and take it as the size of that array.  In multidimensional arrays the leftmost subscript may be omitted and all the others must be specified. The initialisation int x[ ] = {2,4,6,8,10};  makes the array x having 5 elements float a[ ][2] = {{3.2,4.8}, {5.3,3.7}};  makes the array a having 2 rows and 2 columns.
  • 24. #include<stdio.h> void main() { int i,j; int x[2][2]={ {1,50}, {2,75} }; for(i=0;i<2;i++) for(j=0;j<2;j++) printf("nThe value in x[%d][%d] is %d",i,j,x[i][j]); } OUTPUT: The value in x[0][0] is 1 The value in x[0][1] is 50 The value in x[1][0] is 2 The value in x[1][1] is 75
  • 25. #include<stdio.h> void main() { int i,j; int x[][2]={ {1,50},{2,75},{3,65}}; for(i=0;i<=2;i++) for(j=0;j<2;j++) printf("nThe value in x[%d][%d] is %d",i,j,x[i][j]); } OUTPUT: The value in x[0][0] is 1 The value in x[0][1] is 50 The value in x[1][0] is 2 The value in x[1][1] is 75 The value in x[2][0] is 3 The value in x[2][1] is 65
  • 26. /* PROGRAM TO FIND THE MINIMUM VALUE AND ITS POSITION */ #include<stdio.h> #define MAX 5 main( ) { int a[MAX],i,min; int pos = 0; /* Fixing position if the first number is the minimum value */ printf("Enter the array elementsn"); for(i=0;i<MAX;i++) scanf("%d",&a[i]); min=a[0]; for(i=1;i<MAX;i++) if(a[i] < min) { min=a[i]; pos=i; /* Fixing the minimum value position*/ } printf(“ MINIMUM VALUE = %dn”,min); printf(“ POSITION = %dn”,pos); } SAMPLE INPUT AND OUTPUT Enter the array elements 14 29 37 25 45 MINIMUM VALUE = 14 POSITION = 0
  • 27. #define MAXROW 2 #define MAXCOL 4 main( ) { int s[MAXROW][MAXCOL],t[MAXCOL][MAXROW]; int i,j; printf("Enter the values of the matrixn"); for(i=0;i<MAXROW;i++) for(j=0;j<MAXCOL;j++) scanf("%d",&s[i][j]); printf("nGiven Matrixnn"); for(i=0;i<MAXROW;i++) { for(j=0;j<MAXCOL;j++) printf("%dt",s[i][j]); printf("n"); }
  • 28. for(i=0;i<MAXCOL;i++) for(j=0;j<MAXROW;j++) t[i][j] = s[j][i]; printf("nTranspose of the matrixnn"); for(i=0;i<MAXCOL;i++) { for(j=0;j<MAXROW;j++) printf("%dt",t[i][j]); printf("n"); } } SAMPLE INPUT AND OUTPUT Enter the values of the matrix 10 20 30 40 50 60 70 80 Given Matrix 10 20 30 40 50 60 70 80 Transpose of the matrix 10 50 20 60 30 70 40 80
  • 29. #include<stdio.h> #include<conio.h> void main() { int i,j,k,r1,r2,c1,c2; int a[5][5],b[5][5],c[5][5]; clrscr(); //step1: printf("n Enter the size of matrix A:"); scanf("%d%d",&r1,&c1); printf("n Enter the size of matrix B: "); scanf("%d%d",&r2,&c2); if((c1==c2)&&(r1==r2)) goto step2; else goto step1; //step2: printf("n Enter the elements of matrix A n"); for(i=0;i<r1;i++) { for(j=0;j<c1;j++) { scanf("%d",&a[i][j]); } } printf("n Enter the elements of matrix B n"); for(i=0;i<r2;i++) { for(j=0;j<c2;j++) { scanf("t%d",&b[i][j]); } }
  • 30. for(i=0;i<r1;i++) { for(j=0;j<c1;j++) { c[i][j]=0; c[i][j]=c[i][j]+a[i][j]+b[i][j]; } } printf("n The resultant matrix after addition of A & B isn"); for(i=0;i<r1;i++) { for(j=0;j<c1;j++) printf("%dt",c[i][j]); printf("n"); } getch(); } OUTPUT: Enter the size of matrix A: 2 2 Enter the size of matrix B: 2 2 Enter the elements of matrix A 2 2 2 2 Enter the elements of matrix B 3 3 3 3 The resultant matrix after addition of A&B is 5 5 5 5
  • 31. /* PROGRAM TO REMOVE THE DUPLICATE ELEMENTS IN AN ARRAY */ #define MAX 5 main( ) { int a[MAX]; int i,j,k,n=MAX,p; for(i=0;i<n;i++) { printf("Enter the value of a[%d]:n",i); scanf("%d",&a[i]); } printf("Array before deleting duplicate elementsn"); for(i=0;i<n;i++) printf("%dt",a[i]); for(i=0;i<n;i++) { for(j=i+1;j<n;j++)
  • 32.  { if(a[i] == a[j]) { p = i ; for(k=j;k<n;k++) a[k] =a[++j]; j = p; n--; } } } putchar('n'); printf("Array after deleting duplicate elementsn"); for(i=0;i<n;i++) printf("%dt",a[i]); putchar('n'); } SAMPLE INPUT AND OUTPUT Enter the value of a[0]: 5 Enter the value of a[1]: 8 Enter the value of a[2]: 5 Enter the value of a[3]: 12 Enter the value of a[4]: 8 Array before deleting duplicate elements 5 8 5 12 8 Array after deleting duplicate elements 5 8 12
  • 33. /* PROGRAM TO SORT AN ARRAY */ #define MAX 5 main( ) { int a[MAX],i,j,temp; printf("Enter the array elementsn"); for(i=0;i<MAX;i++) scanf("%d",&a[i]); for(i=0;i<MAX;i++) for(j=i+1;j<MAX;j++) { if(a[i] >a[j]) Example Programs
  • 34. { temp = a[i]; a[i] = a[j]; a[j] = temp; } } printf("nAscending ordern"); for(i=0;i<MAX;i++) printf("%dt",a[i]); printf("nDescending ordern"); for(i=MAX-1;i>=0;i--) printf("%dt",a[i]); } SAMPLE INPUT AND OUTPUT Enter the array elements 11 15 20 45 15 Ascending order 11 15 15 20 45 Descending order 45 20 15 15 11 Example Programs
  • 35. /*PROGRAM TO CONVERT A 2-D ARRAY TO 1-D ARRAY */ #define MAXROW 3 #define MAXCOL 2 main( ) { int a[MAXROW][MAXCOL],b[MAXROW*MAXCOL]; int i,j,k=0; printf("Enter the matrix elements in row ordern"); for(i=0;i<MAXROW;i++) for(j=0;j<MAXCOL;j++) { scanf("%d",&a[i][j]); Example Programs
  • 36. b[k++] = a[i][j]; } printf("Given two-dimensional arrayn"); for(i=0;i<MAXROW;i++) { for(j=0;j<MAXCOL;j++) printf("%dt",a[i][j]); printf("n"); } printf("Equivalent one-dimensional arrayn"); for(i=0;i<MAXROW*MAXCOL;i++) printf("%dt",b[i]); } SAMPLE INPUT AND OUTPUT Enter the matrix elements in row order 10 15 20 25 30 35 Given two-dimensional array 10 15 20 25 30 35 Equivalent one-dimensional array 10 15 20 25 30 35 Example Programs