An Array is a technique of storing more then one value in to a single variable.This variable is basically an array of different contegous memory location can hold a discte value. Upon the basis of usage, array are of following three types-
One Dimentional
Two Dimentional
Multi Dimentional
One Dimentional Array:-A 1D array is nothing but simple straight array. Declaration:- Data type arrayname [array-length]; Example int arr[5];
It will reserve a memory like this.
Initialization:-
via assignment:- int a[5]; a[5]={3,4,6,7,9};
via scanf():-for(i=0;i<=4;i++) { scanf("%d",&a[i]); }
Write a program that input an integer array of 5 element and display is its content.
via assignment:-
#include< stdio.h>
#include< conio.h>
void main()
{
int a[5];
clrscr();
a[5]={1,3,5,8,6};
printf("%d",a[0],a[1],a[2],a[3],a[4]);
getch();
}
via scanf():-
#include< stdio.h>
#include< conio.h>
void main()
{
int a[5],i;
clrscr();
printf("Enter five number");
for(i=0;i<=4;i++)
{
scanf("%d",&a[i]);
}
printf("Following are your element");
for(i=0;i<=4;i++)
{
prointf("%d",a[i]);
}
getch();
}
Finding maximum in an array.
#include< stdio.h>
#include< conio.h>
void main();
{
int a[5],I,max=-32768;
printf("enter 5 elements :");
for(i=0;i<5;i++)
{
sacnf("%d",&a[i]);
}
for(i=0;i<5;i++)
{
if(a[i>max])
{
max=a[i];
}
printf("The maximum is %d",max);
getch();
}