write an algorithm and c program to add two 2x2 matrics
Answers were Sorted based on User's Feedback
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 |
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 |
What is getch c?
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?
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
What the different types of arrays in c?
What is enumerated data type in c?
typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none
explain what are actual arguments?
What is the -> in c?
write a own function for strstr
what does exit() do?
char *p="name"; printf(p);