Salve, sto realizzando questo programma che prevede l'utilizzo di una matrice monodimensionale.
Realizzare le operazioni di somma di 2 matrici e prodotto scalare di una matrice per un numero reale.
Il tipo di dato matrice deve essere rappresentato come un vettore di reali a 1 dimensione variabile.
Riesco a stampare sia la matrice a che la matrice b , ma la matrice somma non viene stampata.
Come posso risolvere? Grazie.
#include <stdio.h>
#include <stdlib.h>
#define RMAX 10
#define CMAX 10
typedef struct{
	int righe;
	int colonne;
	float elementi[RMAX*CMAX];
}matrice;
void ScrivereMatriceA(matrice *a);
void ScrivereMatriceB(matrice *b);
void ScrivereRighe(matrice *ptr, int r);
void ScrivereColonne(matrice *ptr, int c);
void ScrivereElemento(matrice *ptr, int r, int c, float e);
void StampaMatrice(matrice m);
void SommaMatrici(matrice a, matrice b, matrice *s);
int main(void){
	matrice a;
	matrice b;
	matrice somma;
	//matrice prodotto;
	//float num;
	ScrivereMatriceA(&a);
	ScrivereMatriceB(&b);
	printf("La matrice a e':\n");
	StampaMatrice(a);
	printf("La matrice b e':\n");
	StampaMatrice(b);
	SommaMatrici(a, b, &somma);
	printf("La matrice somma e':\n");
	StampaMatrice(somma);
	//ProdottoMatricePerNum(a, num, &prodotto);
	system("pause");
	return 0;
}
void ScrivereMatriceA(matrice *a){
	ScrivereRighe(a, 3);
	ScrivereColonne(a, 2);
	ScrivereElemento(a,0,0,0); 
	ScrivereElemento(a,0,1,1); //elemento corrispondente alla riga 0 e alla colonna 1 con valore 1 
	ScrivereElemento(a,1,0,2);
	ScrivereElemento(a,1,1,3);
	ScrivereElemento(a,2,0,4);
	ScrivereElemento(a,2,1,5);
	return;
}
void ScrivereMatriceB(matrice *b){
	ScrivereRighe(b, 3);
	ScrivereColonne(b, 2);
	ScrivereElemento(b,0,0,0);
	ScrivereElemento(b,0,1,1);
	ScrivereElemento(b,1,0,2);
	ScrivereElemento(b,1,1,3);
	ScrivereElemento(b,2,0,4);
	ScrivereElemento(b,2,1,5);
	return;
}
void ScrivereRighe(matrice *ptr, int r){
	ptr->righe = r;
	return;
}
void ScrivereColonne(matrice *ptr, int c){
	ptr->colonne = c;
	return;
}
void ScrivereElemento(matrice *ptr, int r, int c, float e){
	ptr->elementi[r * ptr->colonne + c] = e;
	return;
}
void StampaMatrice(matrice m){
	int i = 1;
	while(i <= m.colonne * m.righe){
		printf("%5.2f ",m.elementi[i - 1]);
		if ((i % (m.colonne)) == 0){
			printf("\n");
		}
		i++;
	}
	printf("\n");
	return;
}
void SommaMatrici(matrice a, matrice b, matrice *s){
	int i = 0;
	while(i < a.colonne * a.righe){
		s->elementi[i] = a.elementi[i] + b.elementi[i];
		i++;
	}
	return;
}