One Dimensional Array in C
One dimensional array is an array that has only one subscript specification that is needed to specify a particular element of an array. A one-dimensional array is a structured collection of components (often called array elements) that can be accessed individually by specifying the position of a component with a single index value.
Syntax :
data-type arr_name[array_size];
Example :
Create an integer array with size 5 and then calculate the larger element of that array using the function.
#include<stdio.h>
int max(int arr[], int size)
{
int r, i;
r = arr[0];
for(i = 1; i r)
r = arr[i];
}
return r;
}
int main()
{
int arr[5];
int m, i;
printf("Enter the array elements : ");
for(i = 0; i<5; i++)
scanf("%d", &arr[i]);
m = max(arr, 5);
printf("The largest element is : %d", m);
return 0;
}
Output :
Enter the array elements : 30 45 40 80 50
The largest element is : 80