Two Dimensional Array
जब हमे Data को Row wise और Column wise, Table के Form में arrange करना हो तो हम Two Dimensional Array का उपयोग करते है।
Two Dimensional Array को use करने का तरीका (Syntax)
<type> <Array Name> [row] [column]
int matrix[3][3];
Example : -
d
जब हमे Data को Row wise और Column wise, Table के Form में arrange करना हो तो हम Two Dimensional Array का उपयोग करते है।
Two Dimensional Array को use करने का तरीका (Syntax)
<type> <Array Name> [row] [column]
int matrix[3][3];
Example : -
/* Program to print Two Dimensional Array elements*/
#include<stdio.h>
#include<stdio.h>
#include<conio.h>
int main(void)
{
int matrix[3][3] = {
10,20,30,
40,50,60,
70,80,90
};
int i,j
clrscr();
printf("The Two Dimensional array is :\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d ",matirx[i][j]);
}
printf("\n");
}
getch();
int main(void)
{
int matrix[3][3] = {
10,20,30,
40,50,60,
70,80,90
};
int i,j
clrscr();
printf("The Two Dimensional array is :\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d ",matirx[i][j]);
}
printf("\n");
}
getch();
return 0;
}
}
Output :
The Two Dimensional array is:
10 20 30
40 50 60
70 80 90
10 20 30
40 50 60
70 80 90
Example -2 :
/* Program to calculate sum of two matrices*/
#include<stdio.h>
#include<stdio.h>
#include<conio.h>
int main(void)
{
int m1[3][3];
int m2[3][3];
int i,j, sum;
clrscr();
printf("Enter the 1st matrix :\n");
for(i=0;i<=2;i++)
}
}
printf("Enter the 2nd matrix :\n");
printf("The sum of matrices : \n");
int main(void)
{
int m1[3][3];
int m2[3][3];
int i,j, sum;
clrscr();
printf("Enter the 1st matrix :\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&m1[i][j]);}
}
printf("Enter the 2nd matrix :\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&m2[i][j]);
}
}
printf("The sum of matrices : \n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
sum = m1[i][j]+m2[i][j];
printf("%d ",sum);
}
printf("\n");
}
getch();
return 0;
}
}
Output :
Enter the 1st matrix :
10 20 30
40 50 60
70 80 90
Enter the 2nd matrix :
1 2 3
4 5 6
7 8 9
The sum of matrices :
11 22 33
44 55 66
77 88 99
No comments:
Post a Comment