What are arrays in data in Data Structure?
If you want to make your career in the field of programming, then the first thing you have to learn is the basics of arrays. After that only, you could do the array problem solving questions.
Let us know what an array is.
An array is the collection of elements of the same data type stored at
contiguous memory locations
What are the uses of an
Array?
An array is a collection of elements of the same data type and its size
sequence is fixed.
An array is a derived data type. When we want to store a large amount of
data , or access or manipulate a large amount of data, then we use arrays.
In an Array all elements have the common name.
Arrays work on index numbers. The index of an array starts from 0 and
ends with size-1. The collection of the same data type where each element has a
separate memory location. An array is static and is a part of linear data
structure.
What are the characteristicsof an array?
Have a look at some of the main characteristics of an array?
All the elements of an array have the same name and they are separated
from one another by an index number.
We can modify the elements of an array separately without affecting
other elements.
Index numbers have a very crucial role when we call an element.
The elements of an array are stored in contiguous memory locations.
The size of an array depends on the type of array and numbers of
elements.
Types of Array.
There are basically two types of array.
1. Single dimensional array
2. Multi dimensional array
What is a single dimensional array?
Single dimensional array is an array that is defined with only one
index.
Single dimensional array is used for searching and sorting.
Syntax:
Data type Array name [size];
Example……
int ar [20];
What is multi dimensional array?
Multi dimensional array is that which works with a double index. It is
used for matrix manuculation.
Syntax….
Data type Array name[size][size];
Example…..
Int
ar[30][10];
Write a program to find a sum
of five nos. using Array in C language.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5]={18,10,17,34,21};
int i,s=0;
clrscr();
printf("Entered elements of arrays =");
for(i=0;i<5;i++)
{
printf("\n%d",a[i]);
s=s+a[i];
}
printf("\nSum=%d",s);
getch();
}
OUTPUT
Enter the elements of arrays =
18
10
17
34
21
Sum = 100
Comments
Post a Comment