addition & multiplication of two dimensional array

 

Program that accept values in 2-Dimensional 3 by 3 array and displays the sum of all the elements.

void

main()

{

int arr[3][3], i, j, sum=0;
/*Accepts input from the user and stores it in 2-D array*/
for(i=0;i<3;i++)

{
for(j=0;j<3;j++)

{

printf(“\nEnter the value for A[%d][%d]: “,i,j);

scanf(“%d”,&arr[i][j]);
}
}
/*Calculate sum of elements in 2-D array*/
for(i=0;i<3;i++){
for(j=0;j<3;j++){
sum=sum+arr[i][j];
}
}
/*Display the value of sum*/

printf(“\nThe sum of the elements of 2-D array is %d”, sum);
}

 

Multiplication of two dimensional array

#include<conio.h>
#include<stdio.h>
void main()

{
int a[2][2],b[2][2],c[2][2];  //declare 3 array int type

int i,j,k;

for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf(“%d”,&a[i][j]);//inserting element in array a

}
}

for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf(“%d”,&b[i][j]);//inserting element in array b

}
}

for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
for(k=;k<2;K++)
{
c[i][j]+=a[i][k]*b[i][j];//multiply of a and b

}
}
}

for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf(“%d”,a[i][j]);//printing element of array c

}
}

 

}

 

 

 

 

Registration


A password will be e-mailed to you.

Feedback Form

Name (required)

Email (required)

Feedback