In: Computer Science
C programming
What is an array? Explain by taking an example that how can we take input and output in 1D array?
Array: an array is a sequential collection of elements having the same datatype.
Declaring Array: data_type array_name[array_size];
Example: int array[20];
Example in C language:
#include <stdio.h>
int main()
{
int i;
int array[6]; //Declaring Array
printf("Enter six integer elements: \n");
// input elements and storing it inarray
for(i = 0; i < 6; ++i)
{
scanf("%d", &array[i]);
}
printf("Array elements: \n");
// printing all the elements of an array
for(i = 0; i < 6; ++i)
{
printf("%d\n", array[i]);
}
return 0;
}
Output: