Thread: arrays and pointers

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    8

    arrays and pointers

    does anyone know what is wrong with this?

    Code:
            int iteration;
            int i,j;
            double sum;
    
            for (iteration=0;iteration<20;iteration++)
            {
                    /*x1[i] =1/a[i][i] *(b[i] -(sum on j, except j=i)a[i][j]*x0[j])
                            for i=0,...,4. (2b)*/
                    for (i=0;i<=4;i++)
                    {
                            sum=0;
                            for (j=0;j<=4;j++)
                                    if (i!=j)
                                            sum+=a[i][j]*x0[j];
                            x1[i]=1.0/a[i][i]*(b[i]-sum);
                    }
                    printf("Iteration %d:\n",iteration);
                    for (i=0;i<=4;i++)
                            printf("%15.4e ",x1[i]);
                    printf("\n");
                    //copy x1 to x- for the next iteration
                    memcpy(x0,x1,4*sizeof(double));
            }
    
            //compute and display residue
            for (i=0;i<=4;i++)
                    residue[i]=b[i]-a[i][i]*x1[i];
            printf("Residue:\n");
            for (i=0;i<=4;i++)
                    printf("%12.4e ",residue[i]);
    
            return;
    }
    when i compile, i get the error:

    `residue' undeclared (first use in this function)
    (Each undeclared identifier is reported only once
    for each function it appears in.)

    the line they are talking about is:

    residue[i]=b[i]-a[i][i]*x1[i];
    Last edited by flamehead144; 03-05-2009 at 11:06 AM.

  2. #2
    Registered User
    Join Date
    Sep 2008
    Posts
    58
    Declare it then.

    Code:
    int residue[50];

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  2. Pointers and multi dimensional arrays
    By andrea72 in forum C++ Programming
    Replies: 5
    Last Post: 01-23-2007, 04:49 PM
  3. Passing pointers to arrays of char arrays
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 03-31-2006, 05:31 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Help understanding arrays and pointers
    By James00 in forum C Programming
    Replies: 2
    Last Post: 05-27-2003, 01:41 AM