calculating elements of arrays

This is a discussion on calculating elements of arrays within the C Programming forums, part of the General Programming Boards category; Hi, can someone help me with this? I am a student and we're working on this assignment. We are to ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    1

    calculating elements of arrays

    Hi, can someone help me with this?

    I am a student and we're working on this assignment. We are to write a program that declares three two-dimensional arrays, named first, second, and third. Initialize the first array when it is declared.

    Calculate each element in the second array by taking 27% of each element in the first array. Use pointer notation in this function. Send the name of the first array and the name of the second array as arguments to the function. This function will not return any value.

    Add the first array to the second array and place the sum in the third array. Use array notation in this function. Send the name of the first array, the name of the second array, and the name of the third array as arguments to the function. This function won't return any value.

    Use the following data to initialize only the first array in main.
    1.0 4.0 7.0 10.0
    2.0 5.0 8.0 11.0
    3.0 6.0 9.0 12.0

    use the #define to set up constants for the number of rows and columns in the array:
    #define r 3
    #define c 4.

    Please help, thanks!

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,535
    So can you do any of your homework at all, or are you completely helpless in this task?

    You'll learn more by
    a) trying to do something
    b) any answers we give will be more tuned to your specific problems.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    It looks pretty straightforward:
    Code:
    /* Process */
    a = someval;
    b = a * .27;
    c = a + b;
    The principle is the same except you're working with arrays:
    Code:
    /* Process */
    for ( i = 0; i < r; i++ ) {
      for ( j = 0; j < c; j++ ) {
        b[i][j] = a[i][j] * .27;
        c[i][j] = a[i][j] + b[i][j];
      }
    }
    Swap out the array notation for pointer notation and you're all set. Try to remember next time that difficult problems only seem that way. Most of the time if you dig down a little bit you'll find that the solution is really very simple.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 08-04-2008, 08:27 PM
  2. Comparing elements of character pointer arrays
    By axe in forum C Programming
    Replies: 2
    Last Post: 11-13-2007, 11:20 PM
  3. Calculating # of Elements in Array
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 04-15-2002, 12:08 PM
  4. Pointer of arrays - how do I access their elements?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-11-2001, 11:28 PM
  5. elements of arrays; functions
    By sballew in forum C Programming
    Replies: 6
    Last Post: 09-03-2001, 01:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21