Array Declaration In C

Array Declaration In C


Array Declaration In C

Array Declaration In C





Array Declaration In C

     It is the collection of records is called an array.
     1. Single dimensional array []
     2. Multi dimensional array [] []

Single dimensional array
Program :

#include
#include
#include
void main()
{
int a[10],i,sum=0,avg;
clrscr();
printf("Enter the ten numbers");
for(i=1;i<=10;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<=10;i++)
{
sum=sum+a[i];
}
avg=sum/10;
printf("The given total of ten number is %d",sum);
printf("The given average of ten number is %d",avg);
getch();
}
Multi-Dimensional Array
Program :

#include
#include
#include
void main()
{
int a[3][3],b[3][3],c[3][3],i,j;
clrscr();
printf("Enter the first matrix is :");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the second matrix:");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
scanf("%d",&b[i][j]);
}
}
for(j=1;j<=3;j++)
{
c[i][j]=a[i][j]*b[i][j];
}
}
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
printf("\t%d",c[i][j]);
}
printf("\n");
}
getch();
}

Post a Comment

1 Comments