[Solved] “C” i couldnt understand how i can add two matrises

Introduction

Welcome to the world of matrix addition! Matrix addition is a fundamental operation in linear algebra and is used to add two matrices together. In this tutorial, we will discuss how to add two matrices in the programming language “C”. We will go over the syntax and provide examples to help you understand the concept. By the end of this tutorial, you will have a better understanding of how to add two matrices in “C”. Let’s get started!

Solution

You can add two matrices by performing element-wise addition. This means that you add the corresponding elements of each matrix together. For example, if you have two matrices A and B, then the element in the ith row and jth column of the resulting matrix C would be Cij = Aij + Bij.


I don’t fully understand what your question is, but I can definately show you how to add two matricies of the same length elementwise, if that’s what you’re looking for.

#include <stdio>;

int main()
{
    //this part is declaring the two arrays you want to add,
    //and the array you want to store the result in.
    int arrayA[3];
    int arrayB[3];
    int result[3];

    //this part is just initializing the data in the array
    arrayA[0] = 1;
    arrayA[1] = 2;
    arrayA[2] = 3;
    arrayB[0] = 5;
    arrayB[1] = 6;
    arrayB[2] = 7;

    //loops from 0 to 2, and adds the nth element of arrayA and
    // arrayB to store in result
    for(int n =0; n < 3; n++)
    {
        result[n] = arrayA[n] + arrayB[n];
    }

    //at this point, result is the addition of your arrays.
    //You can print it, or whatever it is you wanted to do with it.

    return 0;
}

There are many different things that could be ‘adding matricies’, but this is one of them.

However, the code you submitted looks like you’re trying to store numbers from the keyboard into a 2D array. You’re on the right track there, but on your first nested for loop your inner loop goes too far, so it’s going outside of the array bounds. Try more liek this:

int matris[2][2];

for(int i=0;i<2;i++)
{
    //you had j<4 here. That will put you in invalid memory!
    for(int j=0;j<2;j++)
    {
        printf("Sayi giriniz: "); scanf("%d",&matris[i][j]);
    }
}

//you had i<3 here. That will also put you in invalid memory.
for(int i=0;i<2;i++)
{
    for(int j=0;j<2;j++)
    {
        printf("%d ",matris[i][j]);
    }
        printf("\n");
}

I hope I’ve addressed whatever question you were going for.

İyi şanslar!

solved “C” i couldnt understand how i can add two matrises


Adding two matrices together can be a tricky task, but with the right approach, it can be done with ease. To add two matrices, the number of columns in the first matrix must be equal to the number of rows in the second matrix. The result of the addition will be a matrix with the same number of rows as the first matrix and the same number of columns as the second matrix.

To add two matrices, start by writing out the two matrices side by side. Then, add the corresponding elements in each matrix. For example, if the first matrix is [1, 2, 3] and the second matrix is [4, 5, 6], the result would be [5, 7, 9]. Once you have added all the elements, the result will be the sum of the two matrices.

It is important to note that the order of the matrices matters when adding them together. If the order is reversed, the result will be different. For example, if the first matrix is [1, 2, 3] and the second matrix is [4, 5, 6], the result would be [5, 7, 9]. However, if the order is reversed, the result would be [9, 7, 5].

Adding two matrices together can be a useful tool in mathematics and can be used to solve a variety of problems. With the right approach, it can be done with ease.