answersLogoWhite

0

#include

void f1(int a[]);

int a1[2][2],a2[2][2];
int i,j;

void main()
{
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("enter a1[%d] [%d]\t",i,j);
scanf("%d",&a1[i][j]);
}
printf("\n");
}

for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("enter a2[%d] [%d]\t",i,j);
scanf("%d",&a2[i][j]);
}
printf("\n");
}
f1(a);
}

void f1(int a[])
{

for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("therefor the result is: %d%d\t",a1[i][j]+a2[i][j]);
}
printf("\n");
}
}

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

How do you Write A program in c language for checking a diagonal matrix?

Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.


What is the product of matrix A and C?

It's matrix C.


What are the components of c language?

Compiler and Programmer these are the two components of the C language


How do you implement Hadamard matrix in c?

A Hadamard Matrix is a square matrix composed of 1 or -1. Using a square matrix system the hadamard matrix could be created


Perform addition multiplication subtraction of 2-D array using Operator Overloading in C plus plus?

#include&lt;iostream&gt; #include&lt;vector&gt; #include&lt;random&gt; template&lt;const size_t R, const size_t C&gt; class Matrix { public: using row_type = int[C]; private: // attributes int m_data[R][C]; public: // construction/assignment Matrix (); Matrix (const Matrix&amp; source); Matrix (Matrix&amp;&amp; source); Matrix&amp; operator= (const Matrix&lt;R,C&gt;&amp; source); Matrix&amp; operator= (Matrix&lt;R,C&gt;&amp;&amp; source); ~Matrix () {} public: // accessors row_type&amp; row (const size_t index) { return m_data[index]; } const row_type&amp; row (const size_t index) const { return m_data[index]; } row_type&amp; operator[] (const size_t index) { return m_data[index]; } const row_type&amp; operator[] (const size_t index) const { return m_data[index]; } size_t size() const { return R * C; } size_t rows() const { return R; } size_t cols() const { return C; } public: // operations Matrix&lt;R,C&gt;&amp; operator+= (const Matrix&lt;R,C&gt;&amp;); Matrix&lt;R,C&gt;&amp; operator-= (const Matrix&lt;R,C&gt;&amp;); }; template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;::Matrix() { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] = 0; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;::Matrix(const Matrix&lt;R,C&gt;&amp; source) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] = source.m_data[row][col]; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;::Matrix(Matrix&lt;R,C&gt;&amp;&amp; source) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] = std::move (source.m_data[row][col]); } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;&amp; Matrix&lt;R,C&gt;::operator= (const Matrix&lt;R,C&gt;&amp; source) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] = source.m_data[row][col]; return *this; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;&amp; Matrix&lt;R,C&gt;::operator= (Matrix&lt;R,C&gt;&amp;&amp; source) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] = std::move (source.m_data[row][col]); return *this; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;&amp; Matrix&lt;R,C&gt;::operator+= (const Matrix&lt;R,C&gt;&amp; rhs) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] += rhs.m_data[row][col]; return *this; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;&amp; Matrix&lt;R,C&gt;::operator-= (const Matrix&lt;R,C&gt;&amp; rhs) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] -= rhs.m_data[row][col]; return *this; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt; operator+ (const Matrix&lt;R,C&gt;&amp; lhs, const Matrix&lt;R,C&gt;&amp; rhs) { Matrix&lt;R,C&gt; sum (lhs); return sum += rhs; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt; operator- (const Matrix&lt;R,C&gt;&amp; lhs, const Matrix&lt;R,C&gt;&amp; rhs) { Matrix&lt;R,C&gt; sub (lhs); return sub -= rhs; } template&lt;const size_t R, const size_t C, const size_t R1, const size_t C1&gt; Matrix&lt;R,C1&gt; operator* (const Matrix&lt;R,C&gt;&amp; lhs, const Matrix&lt;R1,C1&gt;&amp; rhs) { static_assert (C==R1, "Matrix dimension mismatch!"); Matrix&lt;R,C1&gt; mul; for (size_t x=0; x!=R; ++x) { for (size_t y=0; y!=C1; ++y) { int prod = 0; for (size_t z=0; z!=C; ++z) { prod += lhs[x][z] * rhs[z][y]; } mul[x][y] = prod; } } return mul; } template&lt;const size_t R, const size_t C&gt; std::ostream&amp; operator&lt;&lt; (std::ostream&amp; os, const Matrix&lt;R,C&gt;&amp; m) { for (size_t row=0; row&lt;R; ++row) { for (size_t col=0; col&lt;C; ++col) { std::cout &lt;&lt; m[row][col] &lt;&lt; '\t'; } std::cout &lt;&lt; std::endl; } return os; } int main() { std::default_random_engine generator; std::uniform_int_distribution&lt;int&gt; distribution (1,9); const size_t rows = 2; const size_t cols = 3; Matrix&lt;rows, cols&gt; a, b; for (size_t row=0; row&lt;rows; ++row) { for (size_t col=0; col&lt;cols; ++col) { a[row][col] = distribution (generator); b[row][col] = distribution (generator); } } std::cout &lt;&lt; "Matrix a:\n\n" &lt;&lt; a &lt;&lt; '\n' &lt;&lt; std::endl; std::cout &lt;&lt; "Matrix b:\n\n" &lt;&lt; b &lt;&lt; '\n' &lt;&lt; std::endl; std::cout &lt;&lt; "Matrix a + b:\n\n" &lt;&lt; a + b &lt;&lt; '\n' &lt;&lt; std::endl; std::cout &lt;&lt; "Matrix a - b:\n\n" &lt;&lt; a - b &lt;&lt; '\n' &lt;&lt; std::endl; Matrix&lt;cols, rows&gt; c; for (size_t row=0; row&lt;rows; ++row) { for (size_t col=0; col&lt;cols; ++col) { c[col][row] = distribution (generator); } } std::cout &lt;&lt; "Matrix c:\n\n" &lt;&lt; c &lt;&lt; '\n' &lt;&lt; std::endl; std::cout &lt;&lt; "Matrix a * c:\n\n" &lt;&lt; a * c &lt;&lt; '\n' &lt;&lt; std::endl; }

Related Questions

C Matrix addition program?

How we can addition Two Matrix plz send coding in C language mahesh dhanotiya astah_mahesh@rediff.com how i can built a square matrix in c,


Program to display multiplication of two matrix?

The matrix multiplication in c language : c program is used to multiply matrices with two dimensional array. This program multiplies two matrices which will be entered by the user.


How do you Write A program in c language for checking a diagonal matrix?

Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.


What is the product of matrix A and C?

It's matrix C.


What two vitamins are needed for calcification process to synthesize bone matrix?

The two "vitamins" are A and C.


A c program to find maximum number in a 3 by 3 matrix?

int matrix[][]; // the matrix to find the max in int max = matrix[0][0]; int r,c; for(r = 0; r &lt; 3; ++r) { for(c = 0; c &lt; 3; ++c) { if(matrix[r][c] &gt; max) { max = matrix[r][c]; } } } // max is now the maximum number in matrix


What are the components of c language?

Compiler and Programmer these are the two components of the C language


Write a programme for substraction of two numbers in c language?

substracion of any two number program in c


Write a program in C plus plus to accept the order of two matrices check the possibility of multiplication and perform the multiplication?

#include&lt;iostream&gt; #include&lt;vector&gt; #include&lt;random&gt; template&lt;const size_t R, const size_t C&gt; class Matrix { public: using row_type = int[C]; private: // attributes int m_data[R][C]; public: // construction/assignment Matrix (); Matrix (const Matrix&amp; source); Matrix (Matrix&amp;&amp; source); Matrix&amp; operator= (const Matrix&lt;R,C&gt;&amp; source); Matrix&amp; operator= (Matrix&lt;R,C&gt;&amp;&amp; source); ~Matrix () {} public: // accessors row_type&amp; row (const size_t index) { return m_data[index]; } const row_type&amp; row (const size_t index) const { return m_data[index]; } row_type&amp; operator[] (const size_t index) { return m_data[index]; } const row_type&amp; operator[] (const size_t index) const { return m_data[index]; } size_t size() const { return R * C; } size_t rows() const { return R; } size_t cols() const { return C; } void randomise(std::uniform_int_distribution&lt;int&gt;&amp; distribution, std::default_random_engine&amp; generator); public: // operations Matrix&lt;R,C&gt;&amp; operator+= (const Matrix&lt;R,C&gt;&amp;); Matrix&lt;R,C&gt;&amp; operator-= (const Matrix&lt;R,C&gt;&amp;); }; template&lt;const size_t R, const size_t C&gt; void Matrix&lt;R,C&gt;::randomise(std::uniform_int_distribution&lt;int&gt;&amp; distribution, std::default_random_engine&amp; generator) { for (size_t row=0; row!=R; ++row) { for (size_t col=0; col!=C; ++col) { m_data[row][col] = distribution (generator); } } } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;::Matrix() { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] = 0; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;::Matrix(const Matrix&lt;R,C&gt;&amp; source) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] = source.m_data[row][col]; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;::Matrix(Matrix&lt;R,C&gt;&amp;&amp; source) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] = std::move (source.m_data[row][col]); } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;&amp; Matrix&lt;R,C&gt;::operator= (const Matrix&lt;R,C&gt;&amp; source) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] = source.m_data[row][col]; return *this; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;&amp; Matrix&lt;R,C&gt;::operator= (Matrix&lt;R,C&gt;&amp;&amp; source) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] = std::move (source.m_data[row][col]); return *this; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;&amp; Matrix&lt;R,C&gt;::operator+= (const Matrix&lt;R,C&gt;&amp; rhs) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] += rhs.m_data[row][col]; return *this; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;&amp; Matrix&lt;R,C&gt;::operator-= (const Matrix&lt;R,C&gt;&amp; rhs) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] -= rhs.m_data[row][col]; return *this; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt; operator+ (const Matrix&lt;R,C&gt;&amp; lhs, const Matrix&lt;R,C&gt;&amp; rhs) { Matrix&lt;R,C&gt; sum (lhs); return sum += rhs; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt; operator- (const Matrix&lt;R,C&gt;&amp; lhs, const Matrix&lt;R,C&gt;&amp; rhs) { Matrix&lt;R,C&gt; sub (lhs); return sub -= rhs; } template&lt;const size_t R, const size_t C, const size_t R1, const size_t C1&gt; Matrix&lt;R,C1&gt; operator* (const Matrix&lt;R,C&gt;&amp; lhs, const Matrix&lt;R1,C1&gt;&amp; rhs) { static_assert (C==R1, "Matrix dimension mismatch!"); Matrix&lt;R,C1&gt; mul; for (size_t x=0; x!=R; ++x) { for (size_t y=0; y!=C1; ++y) { int prod = 0; for (size_t z=0; z!=C; ++z) { prod += lhs[x][z] * rhs[z][y]; } mul[x][y] = prod; } } return mul; } template&lt;const size_t R, const size_t C&gt; std::ostream&amp; operator&lt;&lt; (std::ostream&amp; os, const Matrix&lt;R,C&gt;&amp; m) { for (size_t row=0; row&lt;R; ++row) { for (size_t col=0; col&lt;C; ++col) { std::cout &lt;&lt; m[row][col] &lt;&lt; '\t'; } std::cout &lt;&lt; std::endl; } return os; } int main() { std::default_random_engine generator; std::uniform_int_distribution&lt;int&gt; distribution (1,9); const size_t rows = 2; const size_t cols = 3; Matrix&lt;rows, cols&gt; a, b; a.randomise (distribution, generator); b.randomise (distribution, generator); std::cout &lt;&lt; "Matrix a:\n\n" &lt;&lt; a &lt;&lt; '\n' &lt;&lt; std::endl; std::cout &lt;&lt; "Matrix b:\n\n" &lt;&lt; b &lt;&lt; '\n' &lt;&lt; std::endl; std::cout &lt;&lt; "Matrix a + b:\n\n" &lt;&lt; a + b &lt;&lt; '\n' &lt;&lt; std::endl; std::cout &lt;&lt; "Matrix a - b:\n\n" &lt;&lt; a - b &lt;&lt; '\n' &lt;&lt; std::endl; Matrix&lt;cols, rows&gt; c; c.randomise (distribution, generator); std::cout &lt;&lt; "Matrix c:\n\n" &lt;&lt; c &lt;&lt; '\n' &lt;&lt; std::endl; std::cout &lt;&lt; "Matrix a * c:\n\n" &lt;&lt; a * c &lt;&lt; '\n' &lt;&lt; std::endl; }


How do you implement Hadamard matrix in c?

A Hadamard Matrix is a square matrix composed of 1 or -1. Using a square matrix system the hadamard matrix could be created


A rapid repetitive series of threshold stimuli leading to a single fused sustained contraction is A summation of stimuli B treppe C tetanus D sumation of contraction?

a. summation of stimuli


Perform addition multiplication subtraction of 2-D array using Operator Overloading in C plus plus?

#include&lt;iostream&gt; #include&lt;vector&gt; #include&lt;random&gt; template&lt;const size_t R, const size_t C&gt; class Matrix { public: using row_type = int[C]; private: // attributes int m_data[R][C]; public: // construction/assignment Matrix (); Matrix (const Matrix&amp; source); Matrix (Matrix&amp;&amp; source); Matrix&amp; operator= (const Matrix&lt;R,C&gt;&amp; source); Matrix&amp; operator= (Matrix&lt;R,C&gt;&amp;&amp; source); ~Matrix () {} public: // accessors row_type&amp; row (const size_t index) { return m_data[index]; } const row_type&amp; row (const size_t index) const { return m_data[index]; } row_type&amp; operator[] (const size_t index) { return m_data[index]; } const row_type&amp; operator[] (const size_t index) const { return m_data[index]; } size_t size() const { return R * C; } size_t rows() const { return R; } size_t cols() const { return C; } public: // operations Matrix&lt;R,C&gt;&amp; operator+= (const Matrix&lt;R,C&gt;&amp;); Matrix&lt;R,C&gt;&amp; operator-= (const Matrix&lt;R,C&gt;&amp;); }; template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;::Matrix() { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] = 0; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;::Matrix(const Matrix&lt;R,C&gt;&amp; source) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] = source.m_data[row][col]; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;::Matrix(Matrix&lt;R,C&gt;&amp;&amp; source) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] = std::move (source.m_data[row][col]); } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;&amp; Matrix&lt;R,C&gt;::operator= (const Matrix&lt;R,C&gt;&amp; source) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] = source.m_data[row][col]; return *this; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;&amp; Matrix&lt;R,C&gt;::operator= (Matrix&lt;R,C&gt;&amp;&amp; source) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] = std::move (source.m_data[row][col]); return *this; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;&amp; Matrix&lt;R,C&gt;::operator+= (const Matrix&lt;R,C&gt;&amp; rhs) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] += rhs.m_data[row][col]; return *this; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt;&amp; Matrix&lt;R,C&gt;::operator-= (const Matrix&lt;R,C&gt;&amp; rhs) { for (size_t row=0; row&lt;R; ++row) for (size_t col=0; col&lt;C; ++col) m_data[row][col] -= rhs.m_data[row][col]; return *this; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt; operator+ (const Matrix&lt;R,C&gt;&amp; lhs, const Matrix&lt;R,C&gt;&amp; rhs) { Matrix&lt;R,C&gt; sum (lhs); return sum += rhs; } template&lt;const size_t R, const size_t C&gt; Matrix&lt;R,C&gt; operator- (const Matrix&lt;R,C&gt;&amp; lhs, const Matrix&lt;R,C&gt;&amp; rhs) { Matrix&lt;R,C&gt; sub (lhs); return sub -= rhs; } template&lt;const size_t R, const size_t C, const size_t R1, const size_t C1&gt; Matrix&lt;R,C1&gt; operator* (const Matrix&lt;R,C&gt;&amp; lhs, const Matrix&lt;R1,C1&gt;&amp; rhs) { static_assert (C==R1, "Matrix dimension mismatch!"); Matrix&lt;R,C1&gt; mul; for (size_t x=0; x!=R; ++x) { for (size_t y=0; y!=C1; ++y) { int prod = 0; for (size_t z=0; z!=C; ++z) { prod += lhs[x][z] * rhs[z][y]; } mul[x][y] = prod; } } return mul; } template&lt;const size_t R, const size_t C&gt; std::ostream&amp; operator&lt;&lt; (std::ostream&amp; os, const Matrix&lt;R,C&gt;&amp; m) { for (size_t row=0; row&lt;R; ++row) { for (size_t col=0; col&lt;C; ++col) { std::cout &lt;&lt; m[row][col] &lt;&lt; '\t'; } std::cout &lt;&lt; std::endl; } return os; } int main() { std::default_random_engine generator; std::uniform_int_distribution&lt;int&gt; distribution (1,9); const size_t rows = 2; const size_t cols = 3; Matrix&lt;rows, cols&gt; a, b; for (size_t row=0; row&lt;rows; ++row) { for (size_t col=0; col&lt;cols; ++col) { a[row][col] = distribution (generator); b[row][col] = distribution (generator); } } std::cout &lt;&lt; "Matrix a:\n\n" &lt;&lt; a &lt;&lt; '\n' &lt;&lt; std::endl; std::cout &lt;&lt; "Matrix b:\n\n" &lt;&lt; b &lt;&lt; '\n' &lt;&lt; std::endl; std::cout &lt;&lt; "Matrix a + b:\n\n" &lt;&lt; a + b &lt;&lt; '\n' &lt;&lt; std::endl; std::cout &lt;&lt; "Matrix a - b:\n\n" &lt;&lt; a - b &lt;&lt; '\n' &lt;&lt; std::endl; Matrix&lt;cols, rows&gt; c; for (size_t row=0; row&lt;rows; ++row) { for (size_t col=0; col&lt;cols; ++col) { c[col][row] = distribution (generator); } } std::cout &lt;&lt; "Matrix c:\n\n" &lt;&lt; c &lt;&lt; '\n' &lt;&lt; std::endl; std::cout &lt;&lt; "Matrix a * c:\n\n" &lt;&lt; a * c &lt;&lt; '\n' &lt;&lt; std::endl; }