Thread: Gaussian Elimination Problem

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    8

    Gaussian Elimination Problem

    I'm writing a Gaussian Elimination process for a given matrix, and seem to have gotten the numbers correct. Unfortunantly, the results are printed in a continuous line across the screen, without breaks in rows. Here's my code:
    Code:
      
    #include <stdio.h>
    main()
    {
            FILE *infile;
            int cols, rows, col, row;
            double v0[20], v[20], w0[20], w[20];
            infile = fopen("matrix0.dat", "r");
             if(infile==NULL) {
              printf("The file, 'matrix0.dat', was not found\n");
              exit(0);
             }
            fscanf(infile, "%d" "%d", &rows, &cols);
             for(col=0; col<cols; col++){
              fscanf(infile, "%lf",&v0[col]);
               v[col] = v0[col]/v0[0];
               printf("%7.2f", v[col]);
             }
            printf("\n");
            while(!feof(infile)){
             for(col=0; col<cols; col++){
              fscanf(infile, "%lf", &w0[col]);
               w[col] = w0[col] - w0[0]*v[col];
               printf("%7.2f", w[col]);
             }
            }
            printf("\n");
    }
    I would like to be able to break the w[col] results into rows of 10 each, but I haven't been able to accomplish that using a printf("\n") anywhere. Any help or suggestions would be appreciated.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    8
    It worked perfectly, thank you very much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM