One-dimensional Array in C
A single-dimensional array has only a single subscript. A subscript is a number in brackets that follows an array’s name. This number can identify the number of individual elements in the array. An example should make this clear. For the business expenses program, you could use the following line to declare an array of type float:
A multidimensional array has more than one subscript. A two-dimensional array has two subscripts, a three-dimensional array has three subscripts, and so on. There is no limit to the number of dimensions a C array can have. (There is a limit on total array size, as discussed later in today’s lesson.)
int array[4];
The array is named expenses, and it contains 12 elements. Each of the 12 elements is the exact equivalent of a single float variable.
All of C’s data types can be used for arrays. C array elements are always numbered starting at 0, so the 12 elements of expenses are numbered 0 through 11. In the preceding example, January’s expense total would be stored in expenses[0], February’s in expenses[1], and so on. The expense total for December would be in expenses[11].
![1d-array-in-c-programming-language-androwep](https://androwep.com/wp-content/uploads/2019/09/1d-array-in-c-programming-language-androwep.jpg)
Code 1d array
#include<stdio.h>
int main ()
{
int array[10];
array[0] = 20;
array[1] = 10;
int sum = array[0] + array[1];
printf("Value is = %d", sum);
return 0;
}
Output
Value is = 30
Code Example
#include<stdio.h>
int main()
{
int marks[10], i, n, sum = 0, average;
printf("Enter n: ");
scanf("%d", &m);
for(i=0; i< m; ++i)
{
printf("Enter number%d: ",i+1);
scanf("%d", &marks[i]);
sum += marks[i];
}
average = sum/n;
printf("Average = %d", average);
return 0;
}
Output
Enter n: 5
Enter number1: 45
Enter number2: 35
Enter number3: 38
Enter number4: 31
Enter number5: 49
Average = 39
What is 1d array in C?
One – Dimensional Arrays. Posted on February 25, 2012 January 15, 2018 by yashan. Array – In the C programming language an array is a fixed sequenced collection of elements of the same data type. It is simply a grouping of like type data.
What is array with example?
An array is a data structure that contains a group of elements. Typically these elements are all of the same data type, such as an integer or string. … For example, a search engine may use an array to store Web pages found in a search performed by the user.