fix makefile for hw3 and add hw3/*.dat and main.c

This commit is contained in:
2025-10-13 03:18:15 +09:00
parent 5fb912b414
commit cdcf1a079b
5 changed files with 89 additions and 3 deletions

62
hws/hw3/main.c Normal file
View File

@@ -0,0 +1,62 @@
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
void exit(int status) {
static void (*real_exit)(int) = 0;
if (!real_exit) {
real_exit = dlsym(RTLD_NEXT, "exit");
}
printf("HI");
}
#include "nr.h"
#include "nrutil.h"
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void print_matrix(int m, int n, float **mat) {
int i, j;
for(i = 1; i <= m; i ++) {
for(j = 1; j <= n; j ++) {
printf("%6.2f ", mat[i][j]);
}
printf("\n");
}
}
int main() {
int m, n;
int i, j;
FILE *fp = fopen("lineq1.dat", "r");
if(fp == NULL) {
printf("Error opening file");
exit(1);
}
fscanf(fp, "%d", &m); /* row */
fscanf(fp, "%d", &n); /* col */
float** a = matrix(1, m, 1, n);
for(i = 1;i <= m; i ++) {
for(j = 1;j <= n; j ++) {
fscanf(fp, "%f", &a[i][j]);
}
}
float **b = matrix(1, m, 1, 1);
for(i = 1; i<= m; i++) {
fscanf(fp, "%f", &b[i][1]);
}
fclose(fp);
print_matrix(m, n, a);
print_matrix(m, 1, b);
gaussj(a, n, b, m);
print_matrix(m, n, a);
print_matrix(m, 1, b);
return 0;
}