write an algorithm and c program to add two 2x2 matrics

Answers were Sorted based on User's Feedback



write an algorithm and c program to add two 2x2 matrics..

Answer / gouthami chintala

#include<stdio.h>
#include<conio.h>
void main()
{
int a[2][2],b[2][2],c[2][2];
int i,j;
printf("enter the elements for first matrix");
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
scanf("%d",&a[i][j]);
}
}printf("enter the elements for second matrix");
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("the added matrix is ");
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
printf("%d",c[i][j]);
}
}
}


Is This Answer Correct ?    24 Yes 22 No

write an algorithm and c program to add two 2x2 matrics..

Answer / samuel williamson

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,m,n;
int a[50][50],b[50][50],c[50][50];
clrscr();
printf("
Enter the no. of rows for the matrices
");
scanf("%d",&m);
printf("
Enter the no. of columns for the matrices
");
scanf("%d",&n);
printf("
Enter the elements for the matrix A :
");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("
A[%d][%d]= ",i,j);
scanf("%d", &a[i][j]);
}
}
printf("
Enter the elements for matrix B :
");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("
B[%d][%d]= ",i,j);
scanf("%d",&b[i][j]);
}
}

printf("
MATRIX A:
");
for(i=0;i<m;i++)
{ printf("
");
for(j=0;j<n;j++)
{
printf("%d ", a[i][j]);
}
}

printf("
MATRIX B:
");
for(i=0;i<m;i++)
{ printf("
");
for(j=0;j<n;j++)
{
printf("%d ", b[i][j]);
}
}

printf("
ADDITION OF TWO MATRICES:
MATRIX C:
");
for(i=0;i<m;i++)
{ printf("
");
for(j=0;j<n;j++)
{
c[i][j]=(a[i][j]+b[i][j]);
printf("%d ",c[i][j]);
}
}
getch();
}

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More C Interview Questions

Explain about the constants which help in debugging?

0 Answers  


write a program that prints a pascal triangle based on the user input(like how many stages) in an efficient time and optimized code?

3 Answers   Oracle,


Is there anything like an ifdef for typedefs?

0 Answers  


where do we use volatile keyword?

1 Answers  


What is preprocessor with example?

0 Answers  


what is uses of .net

0 Answers  


How can I find the modification date and time of a file?

0 Answers  


WHO WROTE C LANGUAGE?

4 Answers  


write a program in c to find out the sum of digits of a number.but here is a condition that compiler sums the value from left to right....not right to left..

1 Answers  


How do you define a function?

0 Answers  


What is the c value paradox and how is it explained?

0 Answers  


write a program to print calender using for loop.

1 Answers   HCL, TCS,


Categories