Professional Documents
Culture Documents
WHY ARRAYS?
INTRODUCTION
ARRAY APPLICATIONS
ARRAY DECLARATION
Syntax:
Data type arrayName [ arraySize ];
Examples:
int
list[10];
char num[15];
float hat[20];
ARRAY INITIALIZATION
Example:
int num[10];
int age[5]={2,4,34,3,4};
int age[]={2,4,34,3,4}; - the compiler determines the
size of array by calculating the number of elements in
an array.
LENGTH OF ARRAYS
For Example,
int arr[10];
scanf("%d",&age[2]);
scanf("%d",&age[i]);
printf("%d",age[0]);
printf("%d",age[i]);
SIMPLE PROGRAM
Program
#include <stdio.h>
void main()
{ int marks[5],i;
printf(Input of Array
marks);
Array marks);
%d , i, marks[i]);
TYPES OF ARRAYS
INITIALIZATION
INITIALIZATION
scanf("%f",&b[i][j]);
int main()
for(i=0;i<2;++i)
for(j=0;j<2;++j)
int i,j;
c[i][j]=a[i][j]+b[i][j];
/* Sum of corresponding elements of two arrays. */ }
for(i=0;i<2;++i)
printf("\nSum Of Matrix:");
for(j=0;j<2;++j)
for(i=0;i<2;++i)
for(j=0;j<2;++j)
scanf("%f",&a[i][j]);
printf("%.1f\t",c[i][j]);
if(j==1)
printf("\n");
for(j=0;j<2;++j)
return 0;
OUTPUT
Enter the elements of 1st matrix
Enter a11: 2;
Enter a12: 0.5;
Enter a21: -1.1;
Enter a22: 2;
Enter the elements of 2nd matrix
Enter b11: 0.2;
Enter b12: 0;
Enter b21: 0.23;
Enter b22: 23;
Sum Of Matrix: 2.2 0.5 -0.9 25.0
EXAMPLE
#include<stdio.h>
#include<conio.h>
void main()
},
};
int i, j, k;
clrscr();
int arr[3][3][3]=
for(i=0;i<3;i++)
{
{11, 12, 13},
{14, 15, 16},
{17, 18, 19}
},
{
{21, 22, 23},
{24, 25, 26},
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
printf("%d\t",arr[i][j][k]);
}
printf("\n");
},
printf("\n");
getch();
THANK YOU