Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- struct Matrix {
- int r,c;
- double** a;
- };
- void schodkowanie(struct Matrix* m) {
- int q,s;
- double max_so_far;
- for (int k=0;k<m->c;k++) {
- s=0;
- max_so_far=abs(m->a[k][k]);
- for (int i=k+1;i<m->r;i++) {
- if (abs(m->a[i][k])>max_so_far) {
- max_so_far=abs(m->a[i][k]);
- s=1;
- q=i;
- }
- }
- if (s==1) {
- for (int j=0;j<m->r;j++) {
- double temp=m->a[k][j];
- m->a[k][j]=m->a[q][j];
- m->a[q][j]=temp;
- }
- }
- if (m->a[k][k]==0) return;
- for (int w=k+1;w<m->r;w++) {
- double wsp=m->a[w][k]/m->a[k][k];
- for (int j=k;j<m->c;j++) {
- m->a[w][j]-=m->a[k][j]*wsp;
- }
- }
- }
- }
- int main() {
- struct Matrix* m=malloc(sizeof(*m));
- m->r=3;
- m->c=3;
- m->a=malloc(m->r*sizeof(*m->a));
- for (int i=0;i<m->r;i++) {
- m->a[i]=malloc(m->c*sizeof(**m->a));
- }
- for (int i=0;i<3;i++) {
- for (int j=0;j<3;j++)
- fscanf(stdin, "%lf", &m->a[i][j]);
- }
- schodkowanie(m);
- for (int i=0;i<3;i++) {
- for (int j=0;j<3;j++) {
- printf("%lf ", m->a[i][j]);
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement