Skip to main content
Array in c
An array is a collection of similar data elements.These data element have the
same data type. The elements of the array are stored in consecutive memory
location and are referenced by an index.
Declaration of Arrays
Declaring an array means specifying three things
.Data type-what kind of values it can store,for example int,char,float double.
.Name-to identify the array.
.Size-the maximum number of values that the array can hold.
Write a program to read and display n numbers using an array
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0,n,arr[20];
clrscr();
printf("\n Enter the number of element:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n arr[%d]=",i);
scanf("%d",&arr[i]);
}
printf("\n the array elements are);
for(i=0;i<n;i++)
printf("arr[%d]=%\t",i,arr[i]);
}
Output
Enter the number of element:5
arr[0]=1
arr[1]=2
arr[2]=3
arr[3]=4
arr[4]=5
the array elements are
arr[0]=1 arr[1]=2 arr[2]=3
arr[3]=4 arr[4]=5
Comments
Post a Comment