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 const volatile?

2 Answers  


which is the best antivirus and how to update it

7 Answers   Infosys,


What are header files and explain what are its uses in c programming?

0 Answers  


What is the real time usage volatile?

2 Answers   Polycom,


Why shouldn’t I start variable names with underscores?

0 Answers  






Write a program to remove the C comments(/* */) and C++ comments(//) from a file. The file should be declared in command line.

4 Answers   Persistent, Subex,


explain what is a newline escape sequence?

0 Answers  


What is dynamic variable in c?

0 Answers  


Why is c platform dependent?

0 Answers  


write an algorithm and a program to count the number of elements in a circularly singly linked list

1 Answers   Ignou,


What is the size of array float a(10)?

0 Answers  


any "C" function by default returns an a) int value b) float value c) char value d) a & b

0 Answers  


Categories