One D array
**Definition of array**
Array can be define as a collection of data object which are stored in consecutive memory location with a common variable name.
or
Array is the collection of similar data types or collection of similar entity stored in contiguous memory location.
**Initialization of array**
- Array can be made initialization at the time of declaration itself.
- The general form of array initialization is as below
1.Data type array name[size]
2.Data type array name[size]={element1,element2,element3,.....}
Example:
int a[[4]={1,5,8,4}
char d[3]={'A','R',u'}
Program
#include"stdio.h"
int main()
{
int a[100],i,n;
printf("Enter the number of elements : ");
scanf("%d",&n);
printf("Enter the elements\n");
for(i=0;i<n;i++)
{
printf("Entre the a[%d] : ",i);
scanf("%d",&a[i]);
}
//show one-d array//
printf("1-D Array are:\n");
for(i=0;i<n;i++)
{
printf("%d \t ",a[i]);
}
}
Output are:
Enter the number of elements : 5
Enter the elements
Entre the a[0] : 4
Entre the a[1] : 7
Entre the a[2] : 8
Entre the a[3] : 89
Entre the a[4] : 1
1-D Array are:
4 7 8 89 1
Program
#include"stdio.h"
int main()
{
int a[6]={23,4,56,45,32,3};
printf("Array are:\n");
for(int i=0;i<6;i++)
{
printf("%d\t",a[i]);
}
}
Output are:
Array are:
23 4 56 45 32 3
Comments
Post a Comment