Roll No. Name
31 Shah Deep
32 Barad Karan
33 Lakkad Vatsal
34 Shah Vishesh
What is an Array ?
• It is derived data type.
• The nature of array is static (fix).
• Array is a collection of similar or
homogeneous data type.
• Array is also known subscript
variable
or index variable.
• The lower bond of an array is zero 0.
• The upper bond of an array is n-1.
for ex.-int a[9] is an array that stores 9 integers
• Array index start with zero(0).
• Array end with n-1.
0 1 2 3 4 5 6 7 8
100 102 104 106 108 110 112 114 116
index
elements
Memory address
'
Need for an Array
NEED FOR AN ARRAY
• To store large number of variables of same type under a
single variable.
• E.g.
To store Marks of 50 students.
Record of sales of 100 salesman.
• C allows us to define such tables of items by
using two-dimensional arrays.
•The two dimensional array are declared as
follows-
type array_name[row_size][column_size];
For ex.- int a [3][2];
Data type
Array name Row=3
Column=
2
1. Declaration 2D ARRAY
• To declare an array to syntax is.
• The syntax of 2D array is
datatype arrayname[row] [column];
2.Initializing 2D ARRAY
• Like 1D array ,2D array initialized.
• Tow for loop is used .
ex.-
for (i=0 ;i<3; i++)
{
for (j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
}
}
3.Assessing 2D ARRAY
• For loop is used.
Ex.-
for (i=0; i<3; i++)
{
for(j=0; j<3;j++)
{
printf(“t%d”,a[i][j]);
}
print(“n”);
}
• To print the element of an
array is known as assessing.
/* addition of two matrix/*
#include<stdio.h>
int main()
{
int i,j;
int a[3][3],b[3][3],c[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“enter the matrix a=”);
scanf(“%d”,&a[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“enter the matrix b=”);
scanf(“%d”,&b[i][j]);
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
Printf(“/n addition of two matrix=“);
{
for(i=0;i<3;i++)
{
for(J=0;j<3;j++)
{
printf(“%d”,c[i][j]);
}
printf(“/n”);
}
}
return(0);
}
output:
A= B=
C=
9 8 7
6 5 4
3 2 1
1 2 3
4 5 6
7 8 9
10 10 10
10 10 10
10 10 10
/*subtraction of two matrix/*
#include<stdio.h>
int main()
{
int i,j;
int a[3][3],b[3][3],c[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“enter the matrix a=”);
scanf(“%d”,&a[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“enter the matrix b=”);
scanf(“%d”,&b[i][j]);
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]-b[i][j];
}
}
Printf(“/n substract of two matrix=”);
{
for(i=0;i<3;i++)
{
for(J=0;j<3;j++)
{
printf(“%d”,c[i][j]);
}
printf(“/n”);
}
}
return(0);
}
output:
A= B=
C=
2 3 4
5 6 7
8 9 10
1 2 3
4 5 6
7 8 9
1 1 1
1 1 1
1 1 1
/*multiplication of two matrix/*
#include<stdio.h>
int main()
{
int i,j,k;
int a[3][3],b[3][3],c[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“enter the matrix a=”);
scanf(“%d”,&a[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“enter the matrix b=”);
scanf(“%d”,&b[i][j]);
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=0;
for(k=0;k<3;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf(“n enter the matix a is =”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“t%d”,c[i][j]);
}
printf(“n”);
}
printf(“n enter the matrix b is =”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“t%d”,b[i][j]);
}
printf(“n”);
}
printf(“n the multiplication is =”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“t%d”,c[i][j]);
}
printf(“n”);
}
return(0);
}
output:
A=
B=
AB=
1 2 3
4 5 6
7 8 9
9 8 7
6 5 4
3 2 1
46 28 10
118 73 28
190 118 46
DIFFERENCE
1D
1. 1D Array
contains single
row and
multiple
columns.
2. 1D Array is a
simple
collection of
elements.
3. Ex:-
2d
1. 2D Array
contains
multiple row and
multiple
columns.
2. 2D Array is a
collection of 1D
Array .
3. Ex:-
1 2 3 4
1 2 3 4
A 1 2 3
B 4 5 6
C
7
8 9
ARRAY APPLICATIONS
• Array can be used for sorting
elements.
• Array can perform matrix
operation.
• Array can be used to sum all the
elements.
• Array can be stores elements of
same data type.
• Given a list of test scores, determine the
maximum and minimum scores.
• Read in a list of student names and
rearrange them in alphabetical order
(sorting).
• Given the height measurements of students
in a class, output the names of those
students who are taller than average.
Advantages
&
Disadvantages
Advantages
 It is used to represent multiple data of same type by assigning only
single name.
 It can be used to implement other data structures like –
linked lists , stacks ,queue etc….
 2D array are used to represent matrices.
Disadvantages
 We must know array is static structure It means that array is fixed size.
The memory which is allocated to array can not be increased or
reduced.
 Since array is of fixed size , if we allocate more memory than
requirement then the
memory space will be wasted . And if we allocate less memory than
requirement
than it will create problem.
 The elements of array are stored in consecutive memory location. So
insertions and deletion are very difficult and time consuming.
Array

Array

  • 1.
    Roll No. Name 31Shah Deep 32 Barad Karan 33 Lakkad Vatsal 34 Shah Vishesh
  • 2.
    What is anArray ?
  • 3.
    • It isderived data type. • The nature of array is static (fix). • Array is a collection of similar or homogeneous data type. • Array is also known subscript variable or index variable.
  • 4.
    • The lowerbond of an array is zero 0. • The upper bond of an array is n-1. for ex.-int a[9] is an array that stores 9 integers • Array index start with zero(0). • Array end with n-1. 0 1 2 3 4 5 6 7 8 100 102 104 106 108 110 112 114 116 index elements Memory address
  • 5.
  • 6.
    NEED FOR ANARRAY • To store large number of variables of same type under a single variable. • E.g. To store Marks of 50 students. Record of sales of 100 salesman.
  • 7.
    • C allowsus to define such tables of items by using two-dimensional arrays. •The two dimensional array are declared as follows- type array_name[row_size][column_size]; For ex.- int a [3][2]; Data type Array name Row=3 Column= 2
  • 8.
    1. Declaration 2DARRAY • To declare an array to syntax is. • The syntax of 2D array is datatype arrayname[row] [column]; 2.Initializing 2D ARRAY • Like 1D array ,2D array initialized. • Tow for loop is used . ex.- for (i=0 ;i<3; i++) { for (j=0;j<3;j++) { scanf(“%d”,&a[i][j]); } }
  • 9.
    3.Assessing 2D ARRAY •For loop is used. Ex.- for (i=0; i<3; i++) { for(j=0; j<3;j++) { printf(“t%d”,a[i][j]); } print(“n”); } • To print the element of an array is known as assessing.
  • 10.
    /* addition oftwo matrix/* #include<stdio.h> int main() { int i,j; int a[3][3],b[3][3],c[3][3]; for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(“enter the matrix a=”); scanf(“%d”,&a[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(“enter the matrix b=”); scanf(“%d”,&b[i][j]); }
  • 11.
    for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=a[i][j]+b[i][j]; } } Printf(“/n addition oftwo matrix=“); { for(i=0;i<3;i++) { for(J=0;j<3;j++) { printf(“%d”,c[i][j]); } printf(“/n”); } } return(0); }
  • 12.
    output: A= B= C= 9 87 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10 10 10 10 10 10 10 10 10
  • 13.
    /*subtraction of twomatrix/* #include<stdio.h> int main() { int i,j; int a[3][3],b[3][3],c[3][3]; for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(“enter the matrix a=”); scanf(“%d”,&a[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(“enter the matrix b=”); scanf(“%d”,&b[i][j]); }
  • 14.
    for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=a[i][j]-b[i][j]; } } Printf(“/n substract oftwo matrix=”); { for(i=0;i<3;i++) { for(J=0;j<3;j++) { printf(“%d”,c[i][j]); } printf(“/n”); } } return(0); }
  • 15.
    output: A= B= C= 2 34 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1
  • 16.
    /*multiplication of twomatrix/* #include<stdio.h> int main() { int i,j,k; int a[3][3],b[3][3],c[3][3]; for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(“enter the matrix a=”); scanf(“%d”,&a[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(“enter the matrix b=”); scanf(“%d”,&b[i][j]); }
  • 17.
    for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=0; for(k=0;k<3;k++) { c[i][j]=c[i][j]+a[i][k]*b[k][j]; } } } printf(“n enter thematix a is =”); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(“t%d”,c[i][j]); } printf(“n”); }
  • 18.
    printf(“n enter thematrix b is =”); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(“t%d”,b[i][j]); } printf(“n”); } printf(“n the multiplication is =”); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(“t%d”,c[i][j]); } printf(“n”); } return(0); }
  • 19.
    output: A= B= AB= 1 2 3 45 6 7 8 9 9 8 7 6 5 4 3 2 1 46 28 10 118 73 28 190 118 46
  • 20.
    DIFFERENCE 1D 1. 1D Array containssingle row and multiple columns. 2. 1D Array is a simple collection of elements. 3. Ex:- 2d 1. 2D Array contains multiple row and multiple columns. 2. 2D Array is a collection of 1D Array . 3. Ex:- 1 2 3 4 1 2 3 4 A 1 2 3 B 4 5 6 C 7 8 9
  • 21.
    ARRAY APPLICATIONS • Arraycan be used for sorting elements. • Array can perform matrix operation. • Array can be used to sum all the elements. • Array can be stores elements of same data type.
  • 22.
    • Given alist of test scores, determine the maximum and minimum scores. • Read in a list of student names and rearrange them in alphabetical order (sorting). • Given the height measurements of students in a class, output the names of those students who are taller than average.
  • 23.
  • 24.
    Advantages  It isused to represent multiple data of same type by assigning only single name.  It can be used to implement other data structures like – linked lists , stacks ,queue etc….  2D array are used to represent matrices.
  • 25.
    Disadvantages  We mustknow array is static structure It means that array is fixed size. The memory which is allocated to array can not be increased or reduced.  Since array is of fixed size , if we allocate more memory than requirement then the memory space will be wasted . And if we allocate less memory than requirement than it will create problem.  The elements of array are stored in consecutive memory location. So insertions and deletion are very difficult and time consuming.