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


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