- 3,052
- 1,278
- CPU
- Intel i7 7700K
- Dissipatore
- Bequiet Dark rock pro 4
- Scheda Madre
- Msi pc mate z270
- HDD
- Seagate barracuda 1tb, silicon power NVME 500gb
- RAM
- Patriot viper steel 3733Mhz
- GPU
- Inno 3d gtx 1080 herculez design
- Monitor
- Asus mg279q
- PSU
- Corsair HX750
- Case
- Itek lunar 23
- Net
- Tiscali ftth
- OS
- windows 10,mint,debian,Arch linux
Salve a tutti ho fatto un programma che doveva essere alquanto banale in c tuttavia lo scambio delle diagonali non avviene correttamente. so che sbaglio nel momento in cui la c viene riazzerata,avreste magari una soluzione più efficiente?
C:
#include"matrix.h"
extern struct matrix *scambia_diagonali(const struct matrix *m) {
struct matrix *ret = malloc(sizeof(struct matrix));
ret->cols = m->cols;
ret->rows = m->rows;
ret->data = malloc(sizeof(double)*ret->cols*ret->rows);
double temp;
for (size_t r = 0; r < m->rows; r++)
for (size_t c = 0; c < m->cols; c++) {
if (c == r) {
temp = m->data[r*m->cols + c];
ret->data[r*m->cols + c] = m->data[(r*m->cols) + (m->cols - c - 1)];
ret->data[(r*m->cols) + (m->cols - c - 1)] = temp;
}
if (c == ret->cols - 1)
break;
else
ret->data[r*m->cols + c] = m->data[r*m->cols + c];
}
return ret;
}