0
#include "stdio.h"
#define ROW 4
#define COL 4
void input_matrix (int, int, int A[][4], int B[][4]);
void add_matrix (int, int, int A[][4], int B[][4], int C[][4]);
void loadidentity_matrix (int, int, int D[][4]);

void main (void)
{
int A[ROW][COL];
int B[ROW][COL];
int C[ROW][COL];
int D[ROW][COL];
int i, j;

input_matrix (ROW, COL, A, B);
add_matrix (ROW, COL, A, B, C);
loadidentity_matrix (ROW, COL, D);

for (i=0; i<ROW; i++)
{
	for (j=0; j<ROW; j++)
	{
		printf ("A[%d][%d]=%d\n", i, j, A[i][j]);
		printf ("B[%d][%d]=%d\n", i, j, B[i][j]);
		printf ("C[%d][%d]=%d\n", i, j, C[i][j]);
		printf ("D[%d][%d]=%d\n", i, j, D[i][j]);
	}
}
}

void input_matrix (int R, int C, int A[][4], int B[][4])
{
	int i, j;
	printf ("Enter values for array A\n");
	for (i=0; i<R; i++)
	{
		for (j=0; j<C; j++)
			scanf ("%d", A[i][j]);
	}

	printf ("Enter values for array B\n");
	for (i=0; i<R; i++)
	{
		for (j=0; j<C; j++)
			scanf ("%d", B[i][j]);
	}
}

void add_matrix (int r, int c, int A[][4], int B[][4], int C[][4])
{
	int i, j;
	for (i=0; i<r; i++)
	{
		for (j=0; j<c; j++)
		{
			if (r==c)
			{
			C[i][j]=A[i][j]+B[i][j];
			printf ("C[%d][%d]=%d\n", i, j, C[i][j]);
			}
		}
	}
}
void loadidentity_matrix (int col, int row, int D[][4])
{
	int i, j;
	for (i=0; i<row; i++)
	{
		for (j=0; j<col; j++)
		{
			if (i==j)
				D[i][j]=1;
			else
				D[i][j]=0;
		}
	}
}

whats wrong with the code? can u help? i get general protection error for this code

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by nezachem
0

Is this for a course or for real use? If you intend to actually use the code - I would highly recommend going with an already developed mathematical toolkit for c++, such as VNL (part of VXL). It will most definitely be very optimized an provide all of the functionalities you are looking for.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.