/    /  Basic Programs on Arrays

Basic Programs on Arrays

 

Example Program 1:

 

C program to initialize array and display them.

 

#include<stdio.h>
main()
{
int a[5]={12,23,34,45,56};
int i; 
for(i=0;i<5;i++)
{
printf("%d\t",a[i]);
}
}

 

Output:

 

array
 

Example Program 2:

 

C program to read array elements from the user and display them.

 

#include<stdio.h> 
main()
{
int a[5]; 
int i;
printf("Enter the elements to be inserted into array:"); 
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
printf("the array elements are as follows:"); 
for(i=0;i<5;i++)
{
printf("%d\t",a[i]);
}
}

 

Output:

 

array