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 getch c?

0 Answers  


Snake Game: This is normal snake game which you can find in most of the mobiles. You can develop it in Java, C/C++, C# or what ever language you know.

7 Answers   Accenture, Gridco, IBM, Kevin IT, TCS, Vimukti Technologies,


what is memory leak?

3 Answers  


c language supports bitwise operations, why a) 'c' language is system oriented b) 'c' language is problem oriented c) 'c' language is middle level language d) all the above

0 Answers  


What the different types of arrays in c?

0 Answers  






What is enumerated data type in c?

0 Answers  


typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none

0 Answers  


explain what are actual arguments?

0 Answers  


What is the -> in c?

0 Answers  


write a own function for strstr

1 Answers   LG Soft,


what does exit() do?

3 Answers   Cadence,


char *p="name"; printf(p);

1 Answers  


Categories