Array

Array is the set of variable of same data type.Suppose you need 3 int type variable in a program. You may declare 3 variable as follows:

memory space under a,b,c will be created which can be imagined as follows:

a
b
c

Now imagine you need 100 int type variable. Will you type int a1,a2,a3,a4,…………………, a100; ? It is so much cumbersome and time consuming. Array is a nice way to do this. You can declare 100 int type data by this keyword as follows:

Here mark is the array name. 100 is the size of array. 100 variable name will be mark[0], mark[1], mark[2],mark[3],…. mark[99]. So memory spaces for

can be imagined as follows:

mark[0]
mark[1]
mark[2]
mark[3]
.
.
.
mark[99]

Here 0,1,2,3,……..99 are called index number. Index number starts from 0.

General syntax of declaring array: 
data-type  array-name[size];

Example: 
If data type is float and size is 40 and name is score, then array declaration will be as follows:

Problem:
Input 10 integer numbers from keyboard and show the entered numbers.

Solution:

OUTPUT

Enter 10 integer numbers : 5 8 9 4 3 5 10 0 1
Your entered 10 integer numbers are :
5
8
9
4
3
5
10
0
1

Problem:
Write a program to input 10 integer numbers from keyboard and store the numbers in an array. Finally show the highest number.
Solution:

OUTPUT

Enter 10 integer numbers : 5 8 9 4 3 5 10 0 1
The highest number is : 10


Next Previous