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

what is the output of the program and explain why?? #include<stdio.h> void main ( ) { int k=4,j=0: switch (k) { case 3; j=300; case 4: j=400: case 5: j=500; } printf (ā€œ%d\nā€,j); }

14 Answers   Oracle,


.find the output of the following program? char*myfunc(char*ptr) { ptr +=3; return (ptr); } int main() { char*x,*y; x="HELLO"; y=myfunc(x); printf("y = %s ",y); return 0; }

0 Answers  


Is r written in c?

0 Answers  


Why array starts with index 0

2 Answers  


main() { int age; float ht; printf("Enter height and age"); scanf("%d%d",&height,&age); if((age<=20)&&(ht>=5)) {printf("She loves you");} else {printf("She loves you");} }

2 Answers  






for questions 14,15,16,17 use the following alternatives:a.int b.char.c.string.d.float

1 Answers  


Is it possible to run a c program without using main?If yes HOW??

13 Answers   Wipro,


What is a stream water?

0 Answers  


Write a Program to find whether the given number or string is palindrome.

0 Answers   InterGraph,


What is the need of structure in c?

0 Answers  


WAP &#8211; represent a char in binary format

4 Answers   Motorola, Wipro,


Why do we write return 0 in c?

0 Answers  


Categories