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	
Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!